开发者

Blackberry how to display message in app if device got no internet connection?

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.

开发者_如何学Go

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


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");
            }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜