Requesting permissions on Android wear

你。 提交于 2019-11-30 16:08:46

Short answer: keep your watch app on targetSdkVersion 22.

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

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.

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())));

You should dynamically request the permissions from user on wearable devices just the same way you do on the phone side. Checkout the official tutorial Requesting Permissions on Android Wear

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