Request Permission in Android Cordova plugin does not prompt the user

三世轮回 提交于 2019-12-04 10:02:34

Seems that SYSTEM_ALERT_WINDOW is a special case which has its own permission request mechanism starting with API 23. There's a mention of this in the System Permissions documentation:

There are a couple of permissions that don't behave like normal and dangerous permissions. SYSTEM_ALERT_WINDOW and WRITE_SETTINGS are particularly sensitive, so most apps should not use them. If an app needs one of these permissions, it must declare the permission in the manifest, and send an intent requesting the user's authorization. The system responds to the intent by showing a detailed management screen to the user. For details on how to request these permissions, see the SYSTEM_ALERT_WINDOW and WRITE_SETTINGS reference entries.

And the corresponding reference entry for SYSTEM_ALERT_WINDOW says:

Note: If the app targets API level 23 or higher, the app user must explicitly grant this permission to the app through a permission management screen. The app requests the user's approval by sending an intent with action ACTION_MANAGE_OVERLAY_PERMISSION. The app can check whether it has this authorization by calling Settings.canDrawOverlays().

So, in a nutshell, you can't use cordova.requestPermission() to request SYSTEM_ALERT_WINDOW, you've gotta send that custom intent:

cordova.getActivity().startActivity(new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!