java 如何在android中以编程方式授予“绘制其他应用程序”权限?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40355344/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to programmatically grant the "draw over other apps" permission in android?
提问by Anil Ranga
How can I programmatically grant the permission in Settings -> Apps -> Draw over other apps
in Android? I want to use system alert window but unable to in Android Marshmallow without forcing the user to go through the Settings app and grant the permission first.
如何以编程方式Settings -> Apps -> Draw over other apps
在 Android 中授予权限?我想使用系统警报窗口,但无法在 Android Marshmallow 中使用而不强制用户通过“设置”应用程序并首先授予权限。
回答by Shashank Udupa
You can check and ask for overlay permission to draw over other apps using this
您可以使用此检查并请求覆盖权限以绘制其他应用程序
if (!Settings.canDrawOverlays(this)) {
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, 0);
}
回答by sumit baflipara
if (!Settings.canDrawOverlays(this)) {
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, 0);
}
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"></uses-permission>
回答by Curious Mind
Check this question and the answer:
检查这个问题和答案:
SYSTEM_ALERT_WINDOW - 如何在 Android 6.0 和 targetSdkVersion 23 上自动获得此权限
"Every app that requests the SYSTEM_ALERT_WINDOW permission and that is installed through the Play Store (version 6.0.5 or higher is required), will have granted the permission automatically."
“每个请求 SYSTEM_ALERT_WINDOW 权限并通过 Play 商店安装的应用程序(需要 6.0.5 或更高版本),都会自动授予权限。”