views:

190

answers:

1

Hello

I've just started with programming for the Blackberry device. I'm using version 5 of the API.

I'm building a very simple application which is just a browserfield. So far it's all working great. I can display my browserfield with the content I need.

The problem I'm having now is if the device doesn't have an active internet connection I get the ugly "Error requesting content for" message.

I would need to someone display my own message if the device doesn't have an active connection.

Something like "You need to have an active internet connection to use this application" with an Exit button which closes the app.

I've tried to find this for hours but no luck.

Hopefully it's something relatively easy so I can get help here.

Here's my code so far:

package com.mycompany.webview;

import net.rim.device.api.browser.field2.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;

public class webview extends UiApplication
{
    public static void main(String[] args)
    {
        webview app = new webview();
        app.enterEventDispatcher();
    }
    public webview()
    {
    pushScreen(new webviewScreen());
    }
}
class webviewScreen extends MainScreen
{
    public webviewScreen()
    {
        BrowserField myBrowserField = new BrowserField();
        add(myBrowserField);
        myBrowserField.requestContent("http://www.google.com");
    }
}

Would really appreciate some help please.

Thanks

A: 

I got it working. If anyone else is wondering how it's done, this is how I did it:

package com.mycompany.webview;

import net.rim.device.api.browser.field2.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.CoverageInfo;

public class webview extends UiApplication
{
    public static void main(String[] args)
    {
        webview app = new webview();
        app.enterEventDispatcher();
    }
    public webview()
    {
    pushScreen(new webviewScreen());
    }
}
class webviewScreen extends MainScreen
{   
    public webviewScreen()
    {
            if (CoverageInfo.isOutOfCoverage())
            {
                UiApplication.getUiApplication().invokeLater(new Runnable()
                {
                    public void run()
                    {
                        Dialog.alert("You need an active internet connection to use this application");
                        System.exit(0);
                    }
                });
            }
            else
            {
                BrowserField myBrowserField = new BrowserField();
                add(myBrowserField);
                myBrowserField.requestContent("http://www.google.com");
            }
    }
}
Johannes