Пример #1
0
  public static void setServiceAlarm(Context context, boolean isOn) {

    Intent i = PollService.newIntent(context);
    PendingIntent pi = PendingIntent.getService(context, 0, i, 0);
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(ALARM_SERVICE);

    if (isOn)
      alarmManager.setInexactRepeating(
          AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime(), POLL_INTERVAL, pi);
    else {
      alarmManager.cancel(pi);
      pi.cancel();
    }
    QueryPreferences.setAlarmOn(context, isOn);
  }
Пример #2
0
 public static boolean isServiceAlarmOn(Context context) {
   Intent i = PollService.newIntent(context);
   PendingIntent pi = PendingIntent.getService(context, 0, i, PendingIntent.FLAG_NO_CREATE);
   return pi != null;
 }