views:

103

answers:

3

HI,

I'm building an Android application requiring internet connection, and I'm using ConnectivityManager to check whether the device is connected to internet or not. Now, what's the best strategy if it's not connected? Should I quit the application and tell the user to first connect to internet? or is there any way to ask the user if he wants to get connected and connect programatically?

Thanks

Jul

A: 

I would suggest the best way would be you try to access some web url (reliable) and then inform user about connectivity issue. If theres an issue accessing URL then ask user to check connectivity. URL selection may be tricky as the internet connectivity may be available through many sources such as gprs, wifi etc and in some cases some sites may be blocked for access.

Gopi
A: 

I would suggest to exit "gracefully", but notify the user that the app requires an active data connection maybe using Toast.makeToast. You really wouldnt be able to "connect" them in code, if they are not connected, it may be because they dont have a data plan, or are not near a wifi connection

If wifi or data connection is off then ask them to enable it and you can launch the activity for them to do so. But just because these are on, does not mean they are connected.

Ryan Conrad
+1  A: 

In my opinion, you should send the user to the Phone Settings (after informing them that they need an Internet connection to continue using the application) so they can connect the system themselves. Ask them if they wish to exit or if they want to enable network connectivity.

AFAIK there's a way to enable WiFi or 3G directly from the application API.

lighthazard
Thanks. I did that using startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS), 0);, but once I'm in the settings how can I go back to my main activity?
jul
the back button on the users device would send them back to your app.
Ryan Conrad