简体   繁体   English

请求的Android权限未在应用权限设置中显示

[英]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 . 我正在开发一个需要INTERNETWRITE_EXTERNAL_STORAGEACCESS_WIFI_STATECHANGE_WIFI_MULTICAST_STATE权限的Cordova应用程序。 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. INTERNETACCESS_WIFI_STATECHANGE_WIFI_MULTICAST_STATE被视为正常权限,根据文档 ,Android将在安装时自动接受它们,用户无法撤消它们。

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: 现在在Cordova创建的MainActivity ,我在if块中添加了此代码,该块检查以确保我们在6.0或更高版本:

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. 问题是,在运行5.1.1的Android设备上,这有效,当我转到应用程序的权限设置时,我会看到所有4个权限。 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. 但是在运行7.0和7.1.1的设备上,我得到一个对话框,要求批准WRITE_EXTERNAL_STORAGE和所有其他权限,因为它们是正常的,不会被要求批准。 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 . 没有INTERNETACCESS_WIFI_STATECHANGE_WIFI_MULTICAST_STATE I have not tested specifically on a 6.0 device but I think I would have the same issue. 我没有在6.0设备上专门测试过,但我想我会遇到同样的问题。

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? 为什么权限没有显示在权限设置中,为什么我无法执行需要这些权限的操作,即使Android说我有权限?

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. 因此,除了WRITE_EXTERNAL_STORAGE之外的所有权限将始终被授予。 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. 好吧,根据Android版本,他们可能有点难找。 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. 例如,在运行android 7.0的模拟器上,我找到了Apps - > MyApp - > Permissions下的所有权限列表,然后单击溢出菜单中的“所有权限”。

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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