java -Permission.android.MANAGE_USB在Jellybean中起作用,但在Lollipop OS中不起作用
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java -Permission.android.MANAGE_USB在Jellybean中起作用,但在Lollipop OS中不起作用,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4064字,纯文字阅读大概需要6分钟。
内容图文
![java -Permission.android.MANAGE_USB在Jellybean中起作用,但在Lollipop OS中不起作用](/upload/InfoBanner/zyjiaocheng/686/564085032e7648c6a7804c81129274e6.jpg)
我正在开发需要此权限的应用程序:android.permission.MANAGE_USB.
我知道仅在系统应用程序中才授予此权限.
如果我将应用程序安装为android 4.1.2中的系统应用程序,则该应用程序可以正常运行.
但是,如果我尝试将其作为系统应用程序安装在android 5.1中,则调试日志会显示出我没有权限:
错误:
W/System.err: java.lang.SecurityException:
Neither user 10074 nor current process has android.permission.MANAGE_USB.
有人知道为什么它在Android 5.1中一直给我这个错误吗?
表现:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.app">
<uses-permission android:name="android.permission.MANAGE_USB"
android:protectionLevel="signature" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.GET_TASKS"/>
<permission android:name="android.permission.SET_TIME"
android:protectionLevel="signatureOrSystem"
/>
<uses-feature android:name="android.hardware.usb.host"
android:required="true"/>
<application
android:name=".services.AppContext"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
android:supportsRtl="true"
android:hardwareAccelerated="false"
android:theme="@style/AppTheme">
<service android:name=".services.KioskService" android:exported="false"/>
<activity
android:name=".MainActivity"
android:launchMode="singleInstance"
android:stateNotNeeded="true"
android:screenOrientation="sensorLandscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name="com.example.app.services.UsbService"
android:enabled="true">
</service>
<receiver android:name=".services.PowerDisconnectReceiver">
<intent-filter>
<action android:name="android.intent.action.ACTION_POWER_DISCONNECTED"/>
</intent-filter>
</receiver>
<receiver android:name=".services.UsbPermissionReceiver">
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"/>
</intent-filter>
</receiver>
</application>
</manifest>
解决方法:
我会尝试将android:protectionLevel更改为signatureOrSystem:
A permission that the system grants only to applications that are in the Android system image or that are signed with the same certificate as the application that declared the permission. Please avoid using this option, as the signature protection level should be sufficient for most needs and works regardless of exactly where applications are installed. The “signatureOrSystem” permission is used for certain special situations where multiple vendors have applications built into a system image and need to share specific features explicitly because they are being built together.
签名:
A permission that the system grants only if the requesting application is signed with the same certificate as the application that declared the permission. If the certificates match, the system automatically grants the permission without notifying the user or asking for the user’s explicit approval.
我了解您无法访问由谁在设备中编译的Android OS映像所使用的签名密钥,因此签名protectionLevel将不匹配并且不会授予您权限.
看到
https://developer.android.com/guide/topics/manifest/permission-element.html
更新:为了完整性,我在答案中添加了@ carlo.S注释:
In Lollipop, an app to be considered as a system application needs to be installed under the
system/priv-app
folder and notsystem/app
folder like in Android 4.2.2! Also, app needs to have 644 permissions.
当然,设备需要扎根.
内容总结
以上是互联网集市为您收集整理的java -Permission.android.MANAGE_USB在Jellybean中起作用,但在Lollipop OS中不起作用全部内容,希望文章能够帮你解决java -Permission.android.MANAGE_USB在Jellybean中起作用,但在Lollipop OS中不起作用所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。