清单中的权限在 Android 6 中不起作用 [英] Permission from manifest doesn't work in Android 6

查看:22
本文介绍了清单中的权限在 Android 6 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

完全忽略:

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

所以我得到了例外:

Caused by: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@86fb55b -- 此窗口类型的权限被拒绝

Caused by: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@86fb55b -- permission denied for this window type

它甚至没有列出:

我该如何解决?谢谢.

它在配置应用程序/高级/绘制其他应用程序中列出.所以我打开它,现在它工作正常,但是为什么当我运行我的应用程序时没有任何对话框询问权限?所有权限都被默认关闭,我需要转到设置并手动打开它?

It's listed in Configure apps/ Advanced / Draw over other app. So i turn it on and now it works fine, but why there isn't any dialog to ask about permission when i run my app? All perrmissions was turned off by deafult and i need to go to settings and mannualy turn it on?

推荐答案

感谢 CommonsWare 的博文,我得到了一些线索.

Thanks to CommonsWare's blog post, I got some clue.

假设您的代码在 ActivityFragment 中,请检查覆盖权限并在必要时对其进行请求:

Assuming your code is in Activity or Fragment, check the overlay permission and make a request for it if necessary:

public static int OVERLAY_PERMISSION_REQ_CODE = 1234;

public void someMethod() {
    if (!Settings.canDrawOverlays(this)) {
        Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                Uri.parse("package:" + getPackageName()));
        startActivityForResult(intent, OVERLAY_PERMISSION_REQ_CODE);
    }
}

然后,重新检查权限以获得更好的用户体验:

Then, re-check the permission for better UX:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == OVERLAY_PERMISSION_REQ_CODE) {
        if (!Settings.canDrawOverlays(this)) {
            // SYSTEM_ALERT_WINDOW permission not granted...
        }
    }
}

这篇关于清单中的权限在 Android 6 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆