7

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?

ierturk
  • 452
  • 6
  • 22
  • 1
    On ordinary Android devices, [that permission requires a double-opt-in](http://stackoverflow.com/a/32083622/115145), including the user granting the permission in Settings. I do not know what the long-term plan is for permissions like this with Android Things, given that the user may not have any way to work with the Settings app (e.g., no screen). – CommonsWare Feb 16 '17 at 18:32
  • Please file a bug regarding your issue obtaining the permission you need to access the Settings API: https://code.google.com/p/android/issues/entry?template=Android%20Things%20bug%20report – devunwired Feb 20 '17 at 05:07
  • @Devunwired I don't have developer account. So I can't access the service android issues. – ierturk Feb 20 '17 at 15:30
  • 1
    @IbrahimERTURK All you need is any Google account, which you will need sooner or later if you plan to continue developing on any Android-based platform. – devunwired Feb 22 '17 at 03:27
  • Did you able to find solution for write settings in AT with preview 0.4.1? – Herry Jul 18 '17 at 09:40

3 Answers3

9

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

Blundell
  • 75,855
  • 30
  • 208
  • 233
  • According to boot up messages `W/PackageManager: Unknown permission com.android.launcher.permission.WRITE_SETTINGS in package com.android.onetimeinitializer`. Does the message says, there is no way to write to setting on AT? – ierturk Feb 16 '17 at 21:20
  • 1
    I've tried to power on and off. Still, No grant to access settings. @Blundell – ierturk Feb 16 '17 at 21:37
  • I don't think the current version of Android things has System Settings. – shalafi Feb 17 '17 at 16:34
  • @ierturk have you tried after Android Studio 3.0 was released? should work as Blundell said – eOnOe Oct 14 '17 at 03:00
  • 1
    @eOnO this is not regarding version of Android Studio. However, I tried AT up to 5.3, so it need to be granted by user manually. So it needs to be a display and keyboard, or touch screen display to grant permission. Also, with AT 4 and 5.3, there is a bug with AOSP soft keyboard. I have to switch back to version 3. have a look at [link](https://stackoverflow.com/questions/42015209/how-to-show-soft-keyboard-on-android-things#comment80073645_42033832) – ierturk Oct 15 '17 at 02:18
  • thanks for the clarification @ierturk i didn't knew that. – eOnOe Oct 17 '17 at 14:51
  • to show app permissions: `adb shell dumpsys package ` – Milan Rakos Dec 20 '18 at 10:27
0

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.

ierturk
  • 452
  • 6
  • 22
0

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 :

enter image description here

Koustuv Ganguly
  • 897
  • 7
  • 21