7

I had an INTERNET permission in my app. But now I want to add google analytics in my app. And it says it need a CHECK_INTERNET_SATE. Do I have to add it? If so, it looks very strange - app, which can access internet can't read it's state. I don't think it's normal

kandi
  • 1,098
  • 2
  • 12
  • 24

1 Answers1

13

There is a basic difference between these 2 permissions,

<uses-permission android:name="android.permission.INTERNET" />

The above permission Allows applications to open network sockets.

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Where as above ACCESS_NETWORK_STATE permission Allows applications to access information about networks.

Example:

If you want to load a URL in a WebView, you only need android.permission.INTERNET permission.

If there is a situation where you have to download some data from a server, you need to check internet connection availability before downloading. Otherwise app may crash if there is no connectivity.Like following ways, you can check internet connectivity,

public boolean isOnline() {
    ConnectivityManager cm =
        (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    if (netInfo != null && netInfo.isConnectedOrConnecting()) {
        return true;
    }
    return false;
}

In the above snippet, you are fetching information about the network so here you have to take android.permission.ACCESS_NETWORK_STATE permission.

And it says it need a CHECK_INTERNET_SATE. Do I have to add it?

Google Analytics SDK checks network availability before sending information to the server so you need that permission too.

Hope it clears your doubt.

reference

http://developer.android.com/reference/android/Manifest.permission.html

https://stackoverflow.com/a/19642087/1665507

Community
  • 1
  • 1
Spring Breaker
  • 8,233
  • 3
  • 36
  • 60