0

I've a question for you about the possibility to have an application crash if wi-fi is not able, I'm in the midle of the seea, or if it is diasbled:

My application permission about the net in general are:

android.permission.ACCESS_WIFI_STATE
android.permission.ACCESS_NETWORK_STATE
android.permission.INTERNET
android.permission.CHANGE_WIFI_STATE
android.permission.CHANGE_NETWORK_STATE

Some users complain that my app doesn't work if there's not wi-fi connection.

I never have experience about this issue.

Naturally my application doesn't provide only net services.

Thanks and regards

  • You can refer below link http://stackoverflow.com/questions/4238921/android-detect-whether-there-is-an-internet-connection-available – Nirali Jun 07 '12 at 10:31

1 Answers1

0

You should allways check your network connection before doing network requests. To check if you have a netwrok connection you can use the following snippet:

    public static boolean isOnline(Context applicationContext){
    ConnectivityManager cm = (ConnectivityManager) applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE);
    try{ 
        return cm.getActiveNetworkInfo().isConnectedOrConnecting();
    }
    catch(NullPointerException npe){

        return false; //Airplane mode is on
    }
}
Zelleriation
  • 2,834
  • 1
  • 23
  • 23
  • I do it, but I'd like to know if some of you know if some phone carriers have inserted some limitation to external app to work, that use my net permision, if Wi-Fi is not present. – user1254938 Jun 14 '12 at 08:31