在我的android应用程序中,我想在禁用管理员模式时发送通知。这是我的代码:
public class DeviceAdminComponent extends DeviceAdminReceiver {
public CharSequence onDisableRequested(Context context, Intent intent) {
sendNotificationToS3();
return super.onDisableRequested(context, intent);
}
public void onDisabled(Context context, Intent intent) {
sendNotificationToS3();
super.onDisabled(context, intent);
}
private void sendNotificationToS3() {
String notificationMsg = "blabla";
S3ClientTransfer.sendNotification("myfilename.txt", notificationMsg);
}
}
我的AndroidManifex.xml:
. . .
<receiver
android:name=".main.DeviceAdminComponent"
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_DISABLED" />
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
<action android:name="android.app.action.DEVICE_ADMIN_DISABLE_REQUESTED" />
</intent-filter>
</receiver>
还有我的device_admin.xml
<device-admin xmlns:android="http://schemas.android.com/apk/res/android" >
<uses-policies>
<limit-password />
<reset-password />
<force-lock />
</uses-policies>
</device-admin>
因此,此代码有效,但不能始终如一-它并不总是发送通知。例如,当我调试该代码时,将发送通知,否则不会发送。
我想念什么?