请求对 Android Wear 的权限 [英] Requesting permissions on Android wear

查看:24
本文介绍了请求对 Android Wear 的权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个应用程序,它利用了 Android Wear 上的 system_alert_window.由于棉花糖,默认情况下会撤销此权限.我已从电话设置中在电话端应用程序上启用了此权限.但是权限仍然在 android 磨损端应用程序上被拒绝,并导致 android 磨损端应用程序因权限被拒绝异常而崩溃.有没有办法在 Android Wear 端启用此权限?

I have written an application that takes advantage of system_alert_window on android wear. Since marshmallow this permission is revoked by default. I have enabled this permission on the phone side app from the phone settings. But the permission is still denied on the android wear side app and causes the android wear side app to crash with permission denied exception. Is there a way to enable this permission on Android wear side?

推荐答案

简短回答:将您的手表应用保持在 targetSdkVersion 22 上.

Short answer: keep your watch app on targetSdkVersion 22.

长答案:此权限不使用通常的 requestPermissions() 流程.文档中有更多信息,但归结为一个特殊的设置 UI 供用户启用此权限 - 谷歌似乎没有在 Wear 上实现该 UI.没有它,任何(非系统)应用程序都不能被授予此权限,任何尝试使用它的应用程序都会因如下错误而崩溃:

Long answer: this permission doesn't use the usual requestPermissions() flow. There's more info in the docs, but it boils down to a special Settings UI for the user to enable this permission - and it doesn't appear that Google has implemented that UI on Wear. Without it, no (non-system) app can be granted this permission, and any app which tries to use it will crash on an error like the following:

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

但是,此限制仅适用于面向 SDK 级别 23(及更高级别)的应用.因此,暂时将您的应用保持在 22,希望 Google 能够在您需要增加它之前填补这个空白.

But, this restriction only applies to apps targeting SDK level 23 (and above). So keep your app on 22 for the time being, and hopefully Google will fill this gap before you need to increment it.

2016 年 12 月 22 日更新:此问题已在 Android Wear 2.0 上修复.对于 Wear 1.x,仍然没有比上述更好的解决方案,但 Google 已经为 Wear 2 实现了权限 UI,当它发布时,手表应用程序应该能够以标准意图链接到它:

UPDATE 22-Dec-2016: This issue is fixed on Android Wear 2.0. There's still no better solution than the above for Wear 1.x, but Google has implemented the permission UI for Wear 2, and when that's released watch apps should be able to link to it with the standard intent:

startActivity(new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
        Uri.parse("package:" + getPackageName())));

这篇关于请求对 Android Wear 的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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