问题
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
?
回答1:
Like you said, the documents say:
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.
Therefore you don't see the normal Android permissions UI.
From the release notes:
Dangerous permissions requested by apps are not granted until the next device reboot. This includes new app installs and new elements in existing apps.
So try powering off and on your Android Things device
回答2:
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.
回答3:
This permission is having Protection level: signature
.Which means this permission is only granted to system apps.
Please find the below screenshot for your reference :
来源:https://stackoverflow.com/questions/42281907/how-to-request-permission-on-android-things