简体   繁体   中英

Requested Android permissions not showing in app permission settings

I'm working on a Cordova app that needs the permissions INTERNET , WRITE_EXTERNAL_STORAGE , ACCESS_WIFI_STATE , and CHANGE_WIFI_MULTICAST_STATE . I have requested these permissions in the manifest like so

<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="27" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />

INTERNET , ACCESS_WIFI_STATE , and CHANGE_WIFI_MULTICAST_STATE are considered normal permissions and according to the docs they will be automatically accepted by Android at install time and the user can't revoke them.

Now in the MainActivity created by Cordova I added this code within an if block that checks to make sure we are on 6.0 or above:

if (checkSelfPermission(Manifest.permission.ACCESS_WIFI_STATE) == PackageManager.PERMISSION_GRANTED &&
                checkSelfPermission(Manifest.permission.CHANGE_WIFI_MULTICAST_STATE) == PackageManager.PERMISSION_GRANTED &&
                checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
            Log.d(TAG, "has permission");
        }
        else {
            Log.d(TAG, "no permission");
            requestPermissions(new String[] { Manifest.permission.ACCESS_WIFI_STATE,
                    Manifest.permission.CHANGE_WIFI_MULTICAST_STATE, Manifest.permission.WRITE_EXTERNAL_STORAGE }, 0);
        }

The problem is that on an Android device running 5.1.1 this works and I see all 4 permissions when I go to the permission settings of the app. However on a device running 7.0 and 7.1.1 I get a dialog asking to approve the WRITE_EXTERNAL_STORAGE and all other permissions, since they are normal, do not get asked for approval. They are automatically approved. The issue is that even though I have permission, on the newer devices I can't do things related to these permissions and if I go to the app settings for permissions all I see is permission Storage granted. Nothing for INTERNET , ACCESS_WIFI_STATE , or CHANGE_WIFI_MULTICAST_STATE . I have not tested specifically on a 6.0 device but I think I would have the same issue.

Why are the permissions not showing in the permission settings, and why cant I perform operations that need these permissions, even though Android says I have permission?

The documentation you linked to contains the following statement:

"The system doesn't prompt the user to grant normal permissions, and users cannot revoke these permissions. "

So all permissions except for WRITE_EXTERNAL_STORAGE will always be granted. The only permission you have to ask for is the one which can be revoked.

Why are the permissions not showing in the permission settings

Well, depending on the android version they may be a little hard to find. For example on my emulator running android 7.0, I found a list of all the permissions under Apps -> MyApp -> Permissions, and then clicking "All permissions" in the overflow menu.

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM