Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Posts: 20
Registered: ‎04-29-2010
My Device: Blackberry 8900
My Carrier: O2

How to display message in app if no active internet connection is available?

Hello

 

I'm building a very simple application which is basically just a browserfield.

 

It's all working great but I would need to display a message if the device doesn't have an active internet connection. Something like "You need to have an active internet connection to use this application". Preferably the message should also have an Exit button that closes the app down.

 

Hopefully this is something relatively easy to do I just can't find it anywhere.

 

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

 

I would really appreciate some help with this please.

 

Thanks!

Developer
Posts: 17,012
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: How to display message in app if no active internet connection is available?

coverageinfo gives you the needed information. you can use dialog to display a dialog
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Contributor
Posts: 20
Registered: ‎04-29-2010
My Device: Blackberry 8900
My Carrier: O2

Re: How to display message in app if no active internet connection is available?

Thanks Simon. Really appreciate you taking the time to reply.

 

Would you be able to give me an example of how I can use this?

 

Thank you

Contributor
Posts: 20
Registered: ‎04-29-2010
My Device: Blackberry 8900
My Carrier: O2

Re: How to display message in app if no active internet connection is available?

Solved it! Maybe not the best solution but it works.

 

Here's the code now:

 

 

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