Back to project page Android-Universal-Notifier.
The source code is released under:
Apache License
If you think the Android project Android-Universal-Notifier listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.mairos.universalnotifier.model; /* w ww . j a v a 2 s . c o m*/ import java.util.Date; import android.annotation.SuppressLint; import android.app.AlarmManager; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.os.PowerManager; public class AlarmManagerBroadcastReceiver extends BroadcastReceiver { public static final String ALARM_MODE = "alarm_mode"; public static final String ALARM_MODE_UPDATE_TASKS = "alarm_mode_update_tasks"; public static final String ALARM_MODE_EXECUTE_TASK = "alarm_mode_execute_task"; public static final String CURRENT_TASKS = "current_tasks"; @SuppressLint("Wakelock") @Override public void onReceive(Context context, Intent intent) { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "NOTIFICATION_SERVICE"); wl.acquire(); Bundle extras = intent.getExtras(); if(extras != null && extras.getString(ALARM_MODE).equals(ALARM_MODE_UPDATE_TASKS)){ TasksQueue tq = TasksQueue.getInstance(context); tq.loadAndScheduleCurrentTasks(Const.FROM_WEB); } else if (extras != null && extras.getString(ALARM_MODE).equals(ALARM_MODE_EXECUTE_TASK)){ String task_name = extras.getString(NotificationTask.TASK_NAME); TasksQueue tq = TasksQueue.getInstance(context); if(tq.getTasksMap().containsKey(task_name)){ NotificationTask nt = tq.getTasksMap().get(task_name); if(nt.getRepeatable() && nt.getFinishTime().getTime() < (new Date()).getTime()){ nt.setSheduled(false); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intentAM = new Intent(context, AlarmManagerBroadcastReceiver.class); PendingIntent pi = PendingIntent.getBroadcast(context, nt.hashCode(), intentAM, 0); am.cancel(pi); } else { tq.executeTask(task_name); } } } wl.release(); } }