سؤال

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?

هل كانت مفيدة؟

المحلول

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?

نصائح أخرى

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?

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top