Android Open Source - Android-Universal-Notifier Alarm Manager Broadcast Receiver






From Project

Back to project page Android-Universal-Notifier.

License

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.

Java Source Code

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();
  }
}




Java Source Code List

com.mairos.universalnotifier.UI.LogFragmentTab.java
com.mairos.universalnotifier.UI.MainActivity.java
com.mairos.universalnotifier.UI.SettingsActivity.java
com.mairos.universalnotifier.UI.TabListener.java
com.mairos.universalnotifier.UI.TaskInfoActivity.java
com.mairos.universalnotifier.UI.TasksFragmentTab.java
com.mairos.universalnotifier.model.AlarmManagerBroadcastReceiver.java
com.mairos.universalnotifier.model.AttachmentData.java
com.mairos.universalnotifier.model.Const.java
com.mairos.universalnotifier.model.JSInterpreter.java
com.mairos.universalnotifier.model.LauncherBroadcastReceiver.java
com.mairos.universalnotifier.model.Logger.java
com.mairos.universalnotifier.model.NotificationService.java
com.mairos.universalnotifier.model.NotificationTask.java
com.mairos.universalnotifier.model.TasksQueue.java
com.mairos.universalnotifier.model.TasksXMLLoader.java
com.mairos.universalnotifier.network.GMailSender.java
com.mairos.universalnotifier.network.JSSEProvider.java
com.mairos.universalnotifier.network.NetworkOperations.java
com.mairos.universalnotifier.network.SMSSender.java