android管理员无效或未列入白名单

时间:2015-04-07 23:19:09

标签: android mobile

我的安卓代码如下:

Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,mDeviceAdmin);
startActivityForResult(intent, RESULT_ENABLE);

然而,它没有按预期打开管理界面,它抛出了一个异常并导致我的Android应用程序崩溃。

java.lang.SecurityException: Admin is invalid or not white-listed.

04-01 18:13:54.931 E/DeviceAdminAdd( 2748):     at android.os.Parcel.readException(Parcel.java:1467)

04-01 18:13:54.931 E/DeviceAdminAdd( 2748):     at android.os.Parcel.readException(Parcel.java:1421)

04-01 18:13:54.931 E/DeviceAdminAdd( 2748):     at android.app.admin.IDevicePolicyManager$Stub$Proxy.setSilentActivation(IDevicePolicyManager.java:2631)

04-01 18:13:54.931 E/DeviceAdminAdd( 2748):     at android.app.admin.DevicePolicyManager.setSilentActivation(DevicePolicyManager.java:259)

04-01 18:13:54.931 E/DeviceAdminAdd( 2748):     at com.android.settings.DeviceAdminAdd.onCreate(DeviceAdminAdd.java:191)

04-01 18:13:54.931 E/DeviceAdminAdd( 2748):     at android.app.Fragment.performCreate(Fragment.java:1678)

04-01 18:13:54.931 E/DeviceAdminAdd( 2748):     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:859)

04-01 18:13:54.931 E/DeviceAdminAdd( 2748):     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062)

04-01 18:13:54.931 E/DeviceAdminAdd( 2748):     at android.app.BackStackRecord.run(BackStackRecord.java:684)

1 个答案:

答案 0 :(得分:0)

在清单中:

<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添加到它将工作的接收器