Android“未授予权限”错误

发布于 2024-10-09 11:59:48 字数 1762 浏览 0 评论 0原文

我最近一直在探索设备管理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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

紙鸢 2024-10-16 11:59:48

您的 XML 格式不正确,因为您在指定元数据元素之前关闭了 标记。它应该是这样的:

<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>
</receiver>

想到的其他想法:

  • 在我的项目中,device_admin.xml 文件位于 \res\xml 目录中。也许确保您的 XML 文件在那里?

  • 接收器的 android:label 上需要 @string 吗?例如

android:label="@string/device_admin"

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:

<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>
</receiver>

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.

android:label="@string/device_admin"
  • I'm not sure about this, but do you also need to add a uses-permission XML element to your Manifest.xml too?

南巷近海 2024-10-16 11:59:48

根据 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文