Search in sources :

Example 1 with K9AlarmManager

use of com.fsck.k9.helper.K9AlarmManager in project k-9 by k9mail.

the class BootReceiver method purgeSchedule.

/**
     * Cancel any scheduled alarm.
     *
     * @param context
     */
public static void purgeSchedule(final Context context) {
    final K9AlarmManager alarmService = K9AlarmManager.getAlarmManager(context);
    alarmService.cancel(PendingIntent.getBroadcast(context, 0, new Intent() {

        @Override
        public boolean filterEquals(final Intent other) {
            // we want to match all intents
            return true;
        }
    }, 0));
}
Also used : K9AlarmManager(com.fsck.k9.helper.K9AlarmManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 2 with K9AlarmManager

use of com.fsck.k9.helper.K9AlarmManager in project k-9 by k9mail.

the class BootReceiver method receive.

@Override
public Integer receive(Context context, Intent intent, Integer tmpWakeLockId) {
    Timber.i("BootReceiver.onReceive %s", intent);
    final String action = intent.getAction();
    if (Intent.ACTION_BOOT_COMPLETED.equals(action)) {
    //K9.setServicesEnabled(context, tmpWakeLockId);
    //tmpWakeLockId = null;
    } else if (Intent.ACTION_DEVICE_STORAGE_LOW.equals(action)) {
        MailService.actionCancel(context, tmpWakeLockId);
        tmpWakeLockId = null;
    } else if (Intent.ACTION_DEVICE_STORAGE_OK.equals(action)) {
        MailService.actionReset(context, tmpWakeLockId);
        tmpWakeLockId = null;
    } else if (ConnectivityManager.CONNECTIVITY_ACTION.equals(action)) {
        MailService.connectivityChange(context, tmpWakeLockId);
        tmpWakeLockId = null;
    } else if ("com.android.sync.SYNC_CONN_STATUS_CHANGED".equals(action)) {
        K9.BACKGROUND_OPS bOps = K9.getBackgroundOps();
        if (bOps == K9.BACKGROUND_OPS.WHEN_CHECKED_AUTO_SYNC) {
            MailService.actionReset(context, tmpWakeLockId);
            tmpWakeLockId = null;
        }
    } else if (FIRE_INTENT.equals(action)) {
        Intent alarmedIntent = intent.getParcelableExtra(ALARMED_INTENT);
        String alarmedAction = alarmedIntent.getAction();
        Timber.i("BootReceiver Got alarm to fire alarmedIntent %s", alarmedAction);
        alarmedIntent.putExtra(WAKE_LOCK_ID, tmpWakeLockId);
        tmpWakeLockId = null;
        context.startService(alarmedIntent);
    } else if (SCHEDULE_INTENT.equals(action)) {
        long atTime = intent.getLongExtra(AT_TIME, -1);
        Intent alarmedIntent = intent.getParcelableExtra(ALARMED_INTENT);
        Timber.i("BootReceiver Scheduling intent %s for %tc", alarmedIntent, atTime);
        PendingIntent pi = buildPendingIntent(context, intent);
        K9AlarmManager alarmMgr = K9AlarmManager.getAlarmManager(context);
        alarmMgr.set(AlarmManager.RTC_WAKEUP, atTime, pi);
    } else if (CANCEL_INTENT.equals(action)) {
        Intent alarmedIntent = intent.getParcelableExtra(ALARMED_INTENT);
        Timber.i("BootReceiver Canceling alarmedIntent %s", alarmedIntent);
        PendingIntent pi = buildPendingIntent(context, intent);
        K9AlarmManager alarmMgr = K9AlarmManager.getAlarmManager(context);
        alarmMgr.cancel(pi);
    }
    return tmpWakeLockId;
}
Also used : K9AlarmManager(com.fsck.k9.helper.K9AlarmManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) K9(com.fsck.k9.K9)

Aggregations

PendingIntent (android.app.PendingIntent)2 Intent (android.content.Intent)2 K9AlarmManager (com.fsck.k9.helper.K9AlarmManager)2 K9 (com.fsck.k9.K9)1