7

我最近开始探索 android 设备策略管理 API,但遇到了一些困难。我只是在启用设备管理时遇到了问题。我相当确定这是清单条目的问题,但是我不能完全确定问题区域。

清单条目:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example"
      android:versionCode="1"
      android:versionName="1.0">

    <application android:label="DeviceAdminTrial" android:icon="@drawable/icon" android:debuggable="true">
        <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>
    </application>
</manifest> 

错误信息:

12-25 15:42:38.930: WARN/DeviceAdminAdd(394): Unable to retrieve device policy ComponentInfo{com.example/com.example.Receiver}
        org.xmlpull.v1.XmlPullParserException: No android.app.device_admin meta-data

device_admin.xml

<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>
</device-admin>

启用方法:

 enable = (Button)findViewById(R.id.button);
        enable.setOnClickListener(new View.OnClickListener()
        {
         public void onClick(View v)
         {
          Intent intent = new Intent (DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
          intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, receiver);

          startActivityForResult(intent, 1);//1 is enabled, 0 is disabled.
          output.setText(""+policymanager.isAdminActive(receiver));
         }
        });

Receiver 类与此处的示例一样基本:http: //developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/DeviceAdminSample.html

任何帮助或建议将不胜感激。

4

3 回答 3

5

在清单中:

<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>
于 2011-01-06T15:42:52.590 回答
1

检查一下: http ://rootfs.wordpress.com/2010/09/09/android-make-your-application-a-device-administrator/

于 2011-07-26T09:23:47.673 回答
-2

我遇到过同样的问题。MyAdmin 类签名必须是public static

public static class MyAdmin extends DeviceAdminReceiver {

}
于 2012-06-18T04:24:33.227 回答