Search code examples
androidpermissionsandroid-things

How to request permission on Android Things?


I'm trying to write to a value on AT. I've already declared required permission as follow in manifest,

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

And try to request permission at run-time, AT shows windows regarding permission setup. However the switch is not clickable. Regarding AT document

Requesting Permissions at Runtime is not supported because embedded devices aren't guaranteed to have a UI to accept the runtime dialog. Declare permissions that you need in your app's manifest file. All normal and dangerous permissions declared in your app's manifest are granted at install time.

However Settings.System.canWrite() always returns false.

Are there any special methods to enable permission WRITE_SETTINGS?


Solution

  • After install application with the statement on AndroidManifest.xml as follow

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

    It needs to be also run Settings as follow via adb

    adb shell am start -S com.android.settings/.Settings
    

    Then click APPS>YOUR_APP, then click permission.

    Now the switch is clickable. So AT not granted to permission. It needs to be granted manually.