Is a request to invade the Internet while running (Android) required?

Android requires that we request runtime permissions, so that users better understand why en is when permissions are needed. I know this is true for permissions like WRITE_CALENDAR and ACCESS_FINE_LOCATION , but it does not seem to be required for INTERNET. Not strange, because almost all applications use the Internet.

Can I say that I only need to declare it in the manifest?

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

Or should I always check it at runtime?

+5
source share
4 answers

No, you should not request INTERNET permission at run time.

INTERNET belongs to the Normal permissions group, which are automatically granted by the system if they are declared in the manifest, as indicated in this document :

Regular permissions do not directly affect user privacy. If your application displays normal resolution in its manifest, the system automatically provides permission.

+13
source
 <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> Your permission is right but you have to check internet connectivity before using any internet related function . You can check internet connected or not by following function public static boolean isNetworkOnline(Context con) { boolean status = false; try { ConnectivityManager cm = (ConnectivityManager) con .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getNetworkInfo(0); if (netInfo != null && netInfo.getState() == State.CONNECTED) { status = true; } else { netInfo = cm.getNetworkInfo(1); if (netInfo != null && netInfo.getState() == State.CONNECTED) { status = true; } else { status = false; } } } catch (Exception e) { e.printStackTrace(); return false; } return status; } 
+1
source

Internet permissions work like pre-sdk 23. Permissions are granted when installing the application.

INTERNET permissions are considered PROTECTION_NORMAL .

If the application announces in its manifest that it needs normal permission, the system automatically grants this permission during installation. The system does not prompt the user to grant normal permissions, and users cannot revoke these permissions.

Dangerous permission requires managing permissions at runtime. They are also in “permission groups”, so when execution permission is performed for one permission of this group, it does not have to be granted for other permissions from the same group.

Also, at runtime, permssions can be granted and set as the default, which can also be canceled by the user at any time.

+1
source

By default, this is not required. Use it only when you need an internet connection in your application.

0
source

Source: https://habr.com/ru/post/1239046/


All Articles