如何请求对 Android 事物的许可?

How to request permission on Android Things?

我正在尝试写入 AT 上的一个值。我已经在清单中声明了所需的权限,

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

并尝试在 运行 时请求权限,AT 显示 windows 关于权限设置。但是,该开关不可点击。关于ATdocument

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.

然而 Settings.System.canWrite() 总是 returns false.

是否有任何特殊的方法来启用权限WRITE_SETTINGS

就像你说的,文档说:

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.

因此您看不到正常的 Android 权限 UI。

来自发行说明:

Dangerous permissions requested by apps are not granted until the next device reboot. This includes new app installs and new elements in existing apps.

所以请尝试关闭和打开您的 Android Things 设备

安装应用程序后 AndroidManifest.xml 上的语句如下

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

它也需要 运行 Settings 如下 adb

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

然后点击APPS>YOUR_APP,然后点击permission

现在可以点击开关了。所以AT没有授予权限。它需要手动授予。

此权限有 Protection level: signature。这意味着此权限仅授予 系统应用程序

请找到以下屏幕截图供您参考: