0

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

Brigante
  • 1,921
  • 6
  • 23
  • 33
  • Your solution may be wrong if you are using a custom APN that only is user to display only dedicated site. You have to have a way when you use the connection, and know that there is a problem and should be able to show the alert there. The coverage still there but your application is not using that coverage, it is using its own custom coverage enabled by a particular APN, hence your solution is wrong. –  Jun 07 '11 at 11:58

1 Answers1

0

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");
            }
    }
}
Brigante
  • 1,921
  • 6
  • 23
  • 33