Requesting permissions on Android wear

前端 未结 2 1680
逝去的感伤
逝去的感伤 2021-01-03 13:25

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 permi

相关标签:
2条回答
  • 2021-01-03 13:34

    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

    0 讨论(0)
  • 2021-01-03 13:36

    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())));
    
    0 讨论(0)
提交回复
热议问题