Android:onDisable不能始终如一地工作

时间:2019-07-24 04:46:24

标签: android amazon-s3 notifications device-admin

在我的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>

因此,此代码有效,但不能始终如一-它并不总是发送通知。例如,当我调试该代码时,将发送通知,否则不会发送。

我想念什么?

0 个答案:

没有答案