问题
Got this shiny manifest ready to be granted all ze permissions
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="exm.rand.lol">
<uses-permission android:name="com.google.android.things.permission.MODIFY_SCREEN_SETTINGS" />
<uses-permission android:name="com.google.android.things.permission.REBOOT"/>
<application>
<uses-library android:name="com.google.android.things" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.IOT_LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
and yet when I boot up the raspberry pi it fails with this in the logcat
12-01 15:23:19.349 2960 2960 E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{exm.rand.lol/exm.rand.lol.MainActivity}: java.lang.SecurityException: Calling process requires permission com.google.android.things.permission.MODIFY_SCREEN_SETTINGS
I searched high and low, stumbled upon multiple threads on StackOverflow
Android Things permission com.google.android.things.permission.MANAGE_INPUT_DRIVERS not found
How to request permission on Android Things?
but to no avail. Rebooting doesn't do anything, reinstalling doesn't do anything, the only way I found atm to give permissions is to manually grant them through adb like dis
adb shell pm grant exm.rand.lol com.google.android.things.permission.REBOOT
Running latest Preiew 6 of Android Things.
回答1:
With Developer Preview 6, you should use the DeviceManager API. Reboot permission can only be granted to system apps if I'm not wrong, and the Android Things console will never package your APK as a system app.
new DeviceManager().reboot()
回答2:
To summerize things... Altough it's stated in Android Things readme that:
All normal and dangerous permissions declared in your app's manifest are granted at install time.
It's not enough to declare permissions in manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xxx.yyy">
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="com.google.android.things.permission.MODIFY_SCREEN_SETTINGS"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<application>
</application>
</manifest>
You need to restart the device with the installed application.
APPLICATION RIGHTS ARE GRANTED UPON DEVICE RESTART not application restart.
来源:https://stackoverflow.com/questions/47596612/android-things-doesnt-grant-permissions-on-boot-what-gives