requestPermissions()不请求权限

时间:2019-02-08 10:15:00

标签: android permissions

我在我的应用程序中拥有特定的权限,这些权限在使用前经过验证。我获得了我没有授予访问权限的权限,并尝试请求它们,但是我看不到任何请求对话框。

代码:

继承AppCompatActivity的活动。

private fun requestPermissions(missingPermissions: ArrayList<String>) {
    val permissionArray = arrayOfNulls<String>(missingPermissions.size)
    missingPermissions.toArray(permissionArray)

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        requestPermissions(permissionArray, 1) //android.permission.ACCESS_WIFI_STATE
    }
}

onRequestPermissionsResult()上,我收到此权限被拒绝的提示-不知道如何做。

清单:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"
    tools:remove="android:maxSdkVersion"
    tools:node="replace"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"
    tools:remove="android:maxSdkVersion"
    tools:node="replace"/>
<uses-permission android:name="android.permission.WIFI_SERVICE"
    tools:remove="android:maxSdkVersion"
    tools:node="replace"/>
<uses-permission android:name="android.permission.INTERNET"
    tools:remove="android:maxSdkVersion"
    tools:node="replace"/>
<uses-permission android:name="android.permission.BLUETOOTH"
    tools:remove="android:maxSdkVersion"
    tools:node="replace"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"
    tools:remove="android:maxSdkVersion"
    tools:node="replace"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
    tools:remove="android:maxSdkVersion"
    tools:node="replace"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"
    tools:remove="android:maxSdkVersion"
    tools:node="replace"/>
<uses-permission android:name="android.permission.READ_CALENDAR"
    tools:remove="android:maxSdkVersion"
    tools:node="replace"/>
<uses-permission android:name="android.permission.WRITE_CALENDAR"
    tools:remove="android:maxSdkVersion"
    tools:node="replace"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"
    tools:remove="android:maxSdkVersion"
    tools:node="replace"/>

为什么我不能请求特定权限?

1 个答案:

答案 0 :(得分:1)

requestPermissions(permissionArray, 1) //android.permission.ACCESS_WIFI_STATE

ACCESS_WIFI_STATE is a normal permission。您无需在运行时请求它。您要做需要在清单中请求它,但我在那里看不到它。