Android“未授予权限”错误
我最近一直在探索设备管理API,我发现我的代码和android开发网站上的示例代码都无法启用设备管理。
我在启动时遇到的错误是:
12-28 17:24:49.596: WARN/PackageManager(60): Not granting permission android.permission.BIND_DEVICE_ADMIN to package com.example (protectionLevel=2 flags=0x8446)
然后当我尝试启用管理员时:
12-28 17:27:22.426: WARN/DeviceAdminAdd(396): Unable to retrieve device policy ComponentInfo{com.example/com.example.Receiver}
org.xmlpull.v1.XmlPullParserException: No android.app.device_admin meta-data
我将所有权限设置为与清单的要求完全相同:
<activity android:name=".MyActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".Receiver"
android:label="device_admin"
android:permission="android.permission.BIND_DEVICE_ADMIN"/>
<meta-data android:name="android.app.device_admin"
android:resource="@xml/device_admin" />
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED"/>
</intent-filter>
并且设备策略也完全按照清单中规定的要求设置蜜蜂。
<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
<uses-policies>
<limit-password />
<watch-login />
<reset-password />
<force-lock />
<wipe-data />
</uses-policies>
我在获取许可时是否犯了错误,或者如果没有额外的代码签名,设备管理是否不可用?
I've been recently exploring the device administration APIs, and i've found that neither my code, nor the sample code on the android developing website have been able to enable the device administration.
The error i get on launching is:
12-28 17:24:49.596: WARN/PackageManager(60): Not granting permission android.permission.BIND_DEVICE_ADMIN to package com.example (protectionLevel=2 flags=0x8446)
and then this when i try to enable the administrator:
12-28 17:27:22.426: WARN/DeviceAdminAdd(396): Unable to retrieve device policy ComponentInfo{com.example/com.example.Receiver}
org.xmlpull.v1.XmlPullParserException: No android.app.device_admin meta-data
I set all the permissions exactly the same as per the requirements for the manifest:
<activity android:name=".MyActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".Receiver"
android:label="device_admin"
android:permission="android.permission.BIND_DEVICE_ADMIN"/>
<meta-data android:name="android.app.device_admin"
android:resource="@xml/device_admin" />
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED"/>
</intent-filter>
and the device policies are also set exactly as per the requirements stated by the APIs.
<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
<uses-policies>
<limit-password />
<watch-login />
<reset-password />
<force-lock />
<wipe-data />
</uses-policies>
Did i make a mistake in getting the permission or is device administration not available without extra code signing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的 XML 格式不正确,因为您在指定元数据元素之前关闭了
标记。它应该是这样的:想到的其他想法:
在我的项目中,device_admin.xml 文件位于 \res\xml 目录中。也许确保您的 XML 文件在那里?
接收器的 android:label 上需要 @string 吗?例如
我不确定这一点,但是您是否还需要添加 在您的 Manifest.xml 中也使用-permission XML 元素吗?
You have badly formatted XML as you have closed your
<receiver />
tag before the specifying the meta-data element. Here's what it should be:Other thoughts that came to mind:
In my project the device_admin.xml file is in the \res\xml directory. Maybe make sure your XML file is there?
Do you need @string on the android:label for the receiver? e.g.
I'm not sure about this, but do you also need to add a uses-permission XML element to your Manifest.xml too?
根据 http://developer.android.com/guide/publishing/app-签名.html
调试器对其进行签名只是为了编译+运行目的。难道还不能在调试器中运行吗?
according to the http://developer.android.com/guide/publishing/app-signing.html
the debugger signs it just for compiling + running purposes. Wouldn't it still be able to run in the debugger?