简体   繁体   English

Android Things不授予启动权限,这有什么用?

[英]Android Things doesn't grant permissions on boot, what gives?

Got this shiny manifest ready to be granted all ze permissions 准备好这个闪亮的清单被授予所有Ze权限

<?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 但是当我启动树莓派时,它在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 我搜索高低,偶然发现了StackOverflow上的多个线程

Android Things permission com.google.android.things.permission.MANAGE_INPUT_DRIVERS not found 找不到Android Things权限com.google.android.things.permission.MANAGE_INPUT_DRIVERS

How to request permission on Android Things? 如何请求对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 重新启动不会执行任何操作,重新安装不会执行任何操作,我发现atm授予权限的唯一方法是通过adb像dis一样手动授予它们

 adb shell pm grant exm.rand.lol com.google.android.things.permission.REBOOT

Running latest Preiew 6 of Android Things. 运行最新的Android Things Preiew 6。

With Developer Preview 6, you should use the DeviceManager API. 在Developer Preview 6中,您应该使用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. 只有在我没有错的情况下,才能将重新启动权限授予系统应用程序,并且Android Things控制台绝不会将您的APK打包为系统应用程序。

new DeviceManager().reboot()

To summerize things... Altough it's stated in Android Things readme that: 总结事物...虽然在Android Things自述文件中指出:

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. 重新启动设备后授予了应用程序权限,而不是重新启动应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM