当用户尝试删除我已实现DeviceAdminReceiver的应用程序的管理员访问权限时,我尝试接收回调,但是当出现警告对话框时,不会触发DeviceAdminReceiver的onDisableRequested()方法。
我如何实现:
public class DeviceAdminReceiver extends android.app.admin.DeviceAdminReceiver {
@Override
public CharSequence onDisableRequested(Context context, Intent intent) {
CharSequence charSequence= context.getString(R.string.admin_receiver_status_disable_warning);
return charSequence;
}
清单文件:
<receiver
android:name=".child.service.receiver.DeviceAdminReceiver"
android:description="@string/sample_device_admin_description"
android:label="@string/sample_device_admin"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<meta-data
android:name="android.app.device_admin"
android:resource="@xml/device_admin_sample" />
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
<action android:name="android.app.action.DEVICE_ADMIN_DISABLE_REQUESTED" />
<action android:name="android.app.action.DEVICE_ADMIN_DISABLED" />
</intent-filter>
</receiver>
我已经验证了其他功能,例如当用户删除应用程序的admin-access时,onDisabled()方法是否起作用。
Android操作系统:8.0.0