Is the request for internet persmission required at runtime (Android)?

前端 未结 4 757
清歌不尽
清歌不尽 2021-01-18 02:46

For Android, it is required that we ask permissions at runtime to make sure users understand better why en when permissions are needed. I know this is true for permissions l

相关标签:
4条回答
  • 2021-01-18 03:29

    By default it is not required. only use it when you need internet connectivity in your app.

    0 讨论(0)
  • 2021-01-18 03:32

    No, you shouldn't ask for INTERNET permission at runtime.

    INTERNET belongs to the Normal permissions group, which are automatically granted by the system if they're declared in the Manifest, as mentioned in this document:

    Normal permissions do not directly risk the user's privacy. If your app lists a normal permission in its manifest, the system grants the permission automatically.

    0 讨论(0)
  • 2021-01-18 03:34

    Internet permissions work as pre-sdk 23 permissions. Permission is given at installation of the app.

    INTERNET permissions are regarded as PROTECTION_NORMAL.

    If an app declares in its manifest that it needs a normal permission, the system automatically grants the app that permission at install time. The system does not prompt the user to grant normal permissions, and users cannot revoke these permissions.

    Dangerous permission require runtime permission management. They are also in 'permission groups' so once runtime permission is granted for one permission from that group, it does not need to be granted for other permissions from the same group.

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

    0 讨论(0)
  • 2021-01-18 03:49
    <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;
        }
    
    0 讨论(0)
提交回复
热议问题