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
the ACCESS_NETWORK_STATE permission is used to avoid using the internet when it isn't available.
Note: Both the Internet and ACCESS_NETWORK_STATE permissions are normal permissions, which means they're granted at install time and don't need to be requested at runtime.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With