Example #1
1
    /**
     * In order to update notification from the AlarmSender.
     *
     * @param oldName <code>String</code> - old name
     * @param oldDescription <code>String</code> - old description
     * @param oldDate <code>String</code> - old date
     * @param newName <code>String</code> - new name
     * @param newDescription <code>String</code> - new description
     * @param newDate <code>String</code> - new date
     */
    @android.webkit.JavascriptInterface
    public void updateAlarmPerToDoItem(
        String oldName,
        String oldDescription,
        String oldDate,
        String newName,
        String newDescription,
        String newDate) {
      long oldTime = ParseDateToTimeStamp(oldDate);
      Intent oldIntent = new Intent(MainActivity.this, NotificationService.class);
      oldIntent.putExtra("name", oldName);
      oldIntent.putExtra("description", oldDescription);
      oldIntent.putExtra("time", oldTime);
      int oldId = (oldName + oldDescription + oldTime).hashCode();
      oldIntent.setData(Uri.parse(String.valueOf(oldId)));
      PendingIntent oldPendingIntent =
          PendingIntent.getService(
              MainActivity.this, 0, oldIntent, PendingIntent.FLAG_UPDATE_CURRENT);
      AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
      alarmManager.cancel(oldPendingIntent);

      long newTime = ParseDateToTimeStamp(newDate);
      Intent newIntent = new Intent(MainActivity.this, NotificationService.class);
      oldIntent.putExtra("name", newName);
      oldIntent.putExtra("description", newDescription);
      oldIntent.putExtra("time", newTime);
      int newId = (newName + newDescription + newTime).hashCode();
      newIntent.setData(Uri.parse(String.valueOf(newId)));
      PendingIntent newPendingIntent =
          PendingIntent.getService(
              MainActivity.this, 0, newIntent, PendingIntent.FLAG_UPDATE_CURRENT);
      alarmManager.set(AlarmManager.RTC_WAKEUP, newTime, newPendingIntent);
    }
Example #2
0
  public static void LaunchAt(Context in_context, WorkingTime wrk_time) {
    Calendar to_fire = wrk_time.start_date;
    Calendar to_kill = wrk_time.stop_date;

    MUUDebug.Log(cl_nm, "Start time " + to_fire.getTime().toString());
    MUUDebug.Log(cl_nm, "Stop time " + to_kill.getTime().toString());

    AlarmManager alarmManager = (AlarmManager) in_context.getSystemService(Context.ALARM_SERVICE);

    Intent serv_intent = new Intent(in_context, ChkPrice.class);

    PendingIntent pendingIntent =
        PendingIntent.getService(
            in_context.getApplicationContext(),
            SERV_START_REQ_CODE,
            serv_intent,
            PendingIntent.FLAG_CANCEL_CURRENT); // Flag might be adjusted

    Intent killer = new Intent(in_context, SQServiceKiller.class);
    PendingIntent sender =
        PendingIntent.getBroadcast(
            in_context.getApplicationContext(),
            SERV_KILLER_REQ_CODE,
            killer,
            PendingIntent.FLAG_CANCEL_CURRENT);

    alarmManager.cancel(pendingIntent);
    alarmManager.cancel(sender);

    alarmManager.set(AlarmManager.RTC_WAKEUP, to_fire.getTimeInMillis(), pendingIntent);
    alarmManager.set(AlarmManager.RTC_WAKEUP, to_kill.getTimeInMillis(), sender);
  }
  private synchronized void cleanUp() {
    Logger.d("Service cleanUp called");
    this.taskQueue.clear();

    if (this.currentTask != null) {
      this.currentTask.stop();
    }
    // remove all future tasks
    this.measurementExecutor.shutdown();
    // remove and stop all active tasks
    this.measurementExecutor.shutdownNow();
    this.checkin.shutDown();

    this.unregisterReceiver(broadcastReceiver);
    Logger.d("canceling pending intents");

    if (checkinIntentSender != null) {
      checkinIntentSender.cancel();
      alarmManager.cancel(checkinIntentSender);
    }
    if (checkinRetryIntentSender != null) {
      checkinRetryIntentSender.cancel();
      alarmManager.cancel(checkinRetryIntentSender);
    }
    if (measurementIntentSender != null) {
      measurementIntentSender.cancel();
      alarmManager.cancel(measurementIntentSender);
    }
    persistState();
    this.notifyAll();
    phoneUtils.shutDown();
    Logger.i("Shut down all executors and stopping service");
  }
  public void startAlarm(Context cxt) {

    // TODO: need to make interval configurable
    // TODO: need to restart alarm on reboot
    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(cxt);
    String sync_frequency = sharedPrefs.getString(Constants.SYNC_FREQUENCY, null);

    Intent intent = new Intent(cxt, AlarmReceiver.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(cxt, ALARM_ID, intent, 0);
    AlarmManager alarmManager = (AlarmManager) cxt.getSystemService(Context.ALARM_SERVICE);
    // alarmManager.cancel(pendingIntent);

    if (sync_frequency != null) {
      if (sync_frequency.equals("-1")) {
        alarmManager.cancel(pendingIntent);
      } else {
        int i;
        try {
          i = Integer.parseInt(sync_frequency);
          i = Integer.parseInt(sync_frequency);
          alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, 0, (60 * 1000), pendingIntent);
        } catch (NumberFormatException e) {
          alarmManager.cancel(pendingIntent);
        }
      }
    }
  }
    @Override
    public void run() {
      Log.d("PCL", "CacherRunnable");
      AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

      List<AndroidResource> resourceList = getDB().getNullResources();
      if ((resourceList == null) || (resourceList.size() == 0)) {
        alarmMgr.cancel(runCacherPendingIntent);
        return;
      }

      int countFetched = 0;
      for (AndroidResource r : resourceList) {
        try {
          byte[] b = fetchURL(r.getUrl());
          if (b != null) {
            r.setContent(b);
            if ((r.getFlags() & RESOURCE_FLAG_QUESTIONNAIRE) != 0) {
              parseQuestionaire(
                  new ByteArrayInputStream(b),
                  new UrlScanningHandler() {
                    @Override
                    public void registerResource(String url) {
                      QuestionnaireManager.this.registerResource(url, 0);
                    }
                  });
            }
            countFetched++;
          }
        } catch (Exception e) {
          e.printStackTrace();
        }
      }

      List<AndroidResource> after = getDB().getNullResources();
      if ((after == null) || (after.size() == 0)) {
        Log.d("PCL", "CacherRunnable cancelling");
        alarmMgr.cancel(runCacherPendingIntent);
        return;
      }
      /*
      			if (after.size() != resourceList.size() - countFetched) {
      				// Stop cycling if it looks like something is wrong and we aren't making progress
      				// ... to avoid cycling endlessly and draining battery
      				alarmMgr.cancel(runCacherPendingIntent);
      				return;
      			}
      */
      Log.d("PCL", "CacherRunnable rescheduling");
      alarmMgr.set(
          AlarmManager.ELAPSED_REALTIME_WAKEUP,
          SystemClock.elapsedRealtime() + QUESTIONNAIRE_CACHER_RETRY_DELAY,
          runCacherPendingIntent);
    }
 private void handleEnableLocationTracking(boolean enable) {
   if (enable) {
     mTTFF = 0;
     mLastFixTime = 0;
     startNavigating();
   } else {
     mAlarmManager.cancel(mWakeupIntent);
     mAlarmManager.cancel(mTimeoutIntent);
     stopNavigating();
   }
 }
Example #7
0
 public static void cancelAlarms(Context context) {
   AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
   PendingIntent alarmScheduler =
       PendingIntent.getBroadcast(context, 0, new Intent(context, AlarmReceiver.class), 0);
   PendingIntent alarmReset =
       PendingIntent.getBroadcast(
           context, 1, new Intent(context, ResetNotificationsReceiver.class), 0);
   if (alarmMgr != null) {
     alarmMgr.cancel(alarmScheduler);
     alarmMgr.cancel(alarmReset);
   }
 }
 private void hibernate() {
   // stop GPS until our next fix interval arrives
   stopNavigating();
   mFixCount = 0;
   mAlarmManager.cancel(mTimeoutIntent);
   mAlarmManager.cancel(mWakeupIntent);
   long now = SystemClock.elapsedRealtime();
   mAlarmManager.set(
       AlarmManager.ELAPSED_REALTIME_WAKEUP,
       SystemClock.elapsedRealtime() + mFixInterval * 1000,
       mWakeupIntent);
 }
 @Test
 public void cancel_removesMatchingPendingIntentsWithActions() {
   Intent newIntent = new Intent("someAction");
   PendingIntent pendingIntent =
       PendingIntent.getBroadcast(
           Robolectric.application.getApplicationContext(), 0, newIntent, 0);
   alarmManager.set(AlarmManager.RTC, 1337, pendingIntent);
   assertEquals(1, shadowAlarmManager.getScheduledAlarms().size());
   alarmManager.cancel(
       PendingIntent.getBroadcast(Robolectric.application, 0, new Intent("anotherAction"), 0));
   assertEquals(1, shadowAlarmManager.getScheduledAlarms().size());
   alarmManager.cancel(
       PendingIntent.getBroadcast(Robolectric.application, 0, new Intent("someAction"), 0));
   assertEquals(0, shadowAlarmManager.getScheduledAlarms().size());
 }
  @Test
  public void cancel_removesMatchingPendingIntents() {
    Intent newIntent = new Intent(Robolectric.application.getApplicationContext(), String.class);
    PendingIntent pendingIntent =
        PendingIntent.getBroadcast(
            Robolectric.application.getApplicationContext(),
            0,
            newIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    alarmManager.set(AlarmManager.RTC, 1337, pendingIntent);

    Intent newIntent2 = new Intent(Robolectric.application.getApplicationContext(), Integer.class);
    PendingIntent pendingIntent2 =
        PendingIntent.getBroadcast(
            Robolectric.application.getApplicationContext(),
            0,
            newIntent2,
            PendingIntent.FLAG_UPDATE_CURRENT);
    alarmManager.set(AlarmManager.RTC, 1337, pendingIntent2);

    assertEquals(2, shadowAlarmManager.getScheduledAlarms().size());

    Intent newIntent3 = new Intent(Robolectric.application.getApplicationContext(), String.class);
    PendingIntent newPendingIntent =
        PendingIntent.getBroadcast(
            Robolectric.application.getApplicationContext(),
            0,
            newIntent3,
            PendingIntent.FLAG_UPDATE_CURRENT);
    alarmManager.cancel(newPendingIntent);
    assertEquals(1, shadowAlarmManager.getScheduledAlarms().size());
  }
  public static void cancelAlarm(Context context) {
    if (alarmMgr != null && alarmIntent != null) {
      alarmMgr.cancel(alarmIntent);
    }

    if (wakeLock != null) if (wakeLock.isHeld()) wakeLock.release();
  }
 public void cancelAlarm(Context context) {
   Log.d(TAG, "cancelAlarm() called with: " + "context = [" + context + "]");
   Intent intent = new Intent(context, LibraryRenewAlarmBroadcastReceiver.class);
   PendingIntent sender = PendingIntent.getBroadcast(context, 1, intent, 0);
   AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
   alarmManager.cancel(sender);
 }
 /**
  * This method will stop the periodic updates, but only stops the updates if no Challenges are
  * active. This method can be called, when the app is closed.
  *
  * <p>To force a stop of the Updates, set the flag forceStop true. This can be used when no
  * network access is available.
  *
  * @param forceStop Stops the periodic updates, even if tracking is active.
  */
 public void requestStopUpdates(boolean forceStop) {
   if (forceStop || (challengeData.activeChallengeCount() == 0)) {
     AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
     alarmManager.cancel(updaterPendingIntent);
     Log.d(TAG, "stoping periodic updates now");
   }
 }
Example #14
0
  /**
   * Schedules alarms for a single task
   *
   * @param shouldPerformPropertyCheck whether to check if task has requisite properties
   */
  @SuppressWarnings("nls")
  private void scheduleAlarm(Metadata alarm) {
    if (alarm == null) return;

    long taskId = alarm.getValue(Metadata.TASK);
    int type = ReminderService.TYPE_ALARM;

    Context context = ContextManager.getContext();
    Intent intent = new Intent(context, Notifications.class);
    intent.setType("ALARM" + Long.toString(taskId)); // $NON-NLS-1$
    intent.setAction(Integer.toString(type));
    intent.putExtra(Notifications.ID_KEY, taskId);
    intent.putExtra(Notifications.TYPE_KEY, type);

    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);

    long time = alarm.getValue(AlarmFields.TIME);
    if (time == 0 || time == NO_ALARM) am.cancel(pendingIntent);
    else if (time > DateUtilities.now()) {
      if (Constants.DEBUG)
        Log.e("Astrid", "Alarm (" + taskId + ", " + type + ") set for " + new Date(time));
      am.set(AlarmManager.RTC_WAKEUP, time, pendingIntent);
    }
  }
Example #15
0
 public static void cancelAlarmViaIntent(
     Context context, Class<? extends BroadcastReceiver> listenerToCancel) {
   Intent intent = new Intent(context, listenerToCancel);
   PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, 0);
   AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
   alarmManager.cancel(sender);
 }
  private static void setAlarm(final Context context, final String reminder_time) {
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(context, DevotionReminderReceiver.class);
    PendingIntent pi =
        PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    // always cancel current (if any)
    am.cancel(pi);

    if (TextUtils.isEmpty(reminder_time)) {
      return;
    }

    int hour = Integer.parseInt(reminder_time.substring(0, 2));
    int minute = Integer.parseInt(reminder_time.substring(2, 4));
    Calendar c = GregorianCalendar.getInstance();
    c.set(Calendar.HOUR_OF_DAY, hour);
    c.set(Calendar.MINUTE, minute);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);

    if (c.getTimeInMillis() < System.currentTimeMillis()) {
      c.add(Calendar.DAY_OF_YEAR, 1);
    }

    am.setRepeating(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pi);
  }
  @Override
  public void onClick(View v) {
    int id = v.getId();
    switch (id) {
        // stop button listener press
      case R.id.StopButton:
        {
          // to cancel notification
          mNotificationManager.cancel(1);

          // to stop the alarm from repeating
          Intent intent = new Intent(this, StopAlarm.class);
          PendingIntent sender = PendingIntent.getActivity(this, notiRequestCode, intent, 0);
          AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
          am.cancel(sender);
          Toast.makeText(getBaseContext(), " alarm stopped", Toast.LENGTH_LONG).show();
          try {
            boolean test =
                new DeleteReminderNotiCode().execute(Integer.toString(notiRequestCode)).get();
          } catch (Exception ex) {
            ex.printStackTrace();
          }
          // after stopping the alarm, it will redirect you to the main reminder page
          Intent transferintent = new Intent(this, Reminder.class);
          transferintent.putExtra("passuser", user);
          transferintent.putExtra("inputCode", inputCode);
          startActivity(transferintent);
        }
    }
  }
Example #18
0
 private static void cancelNotificationAlarm(Context context) {
   Intent intent = new Intent(context, AlarmReceiver.class);
   PendingIntent pendingIntent =
       PendingIntent.getBroadcast(context, 12345, intent, PendingIntent.FLAG_CANCEL_CURRENT);
   AlarmManager am = (AlarmManager) context.getSystemService(Activity.ALARM_SERVICE);
   am.cancel(pendingIntent);
 }
Example #19
0
  private void handleActivityStarted() {
    Log.w("KeyCachingService", "Incrementing activity count...");

    AlarmManager alarmManager = (AlarmManager) this.getSystemService(ALARM_SERVICE);
    alarmManager.cancel(pending);
    activitiesRunning++;
  }
 @Override
 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
   if (preference == mEnableWeather) {
     // _stop_ alarm or start service
     boolean check = ((CheckBoxPreference) preference).isChecked();
     Intent i = new Intent(getActivity().getApplicationContext(), WeatherRefreshService.class);
     i.setAction(WeatherService.INTENT_REQUEST_WEATHER);
     PendingIntent weatherRefreshIntent = PendingIntent.getService(getActivity(), 0, i, 0);
     if (!check) {
       AlarmManager alarms = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
       alarms.cancel(weatherRefreshIntent);
     } else {
       getActivity().startService(i);
     }
     Settings.System.putInt(
         getActivity().getContentResolver(), Settings.System.USE_WEATHER, check ? 1 : 0);
     return true;
   } else if (preference == mUseCustomLoc) {
     return WeatherPrefs.setUseCustomLocation(
         mContext, ((CheckBoxPreference) preference).isChecked());
   } else if (preference == mShowLoc) {
     Settings.System.putInt(
         getActivity().getContentResolver(),
         Settings.System.WEATHER_SHOW_LOCATION,
         ((CheckBoxPreference) preference).isChecked() ? 1 : 0);
     return true;
   } else if (preference == mUseCelcius) {
     return WeatherPrefs.setUseCelcius(mContext, ((CheckBoxPreference) preference).isChecked());
   }
   return super.onPreferenceTreeClick(preferenceScreen, preference);
 }
Example #21
0
 public static void stopServiceAlarm(Context context, Class<?> service) {
   AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
   Intent i = new Intent(context, service);
   PendingIntent p =
       PendingIntent.getService(context, REQUEST_CODE, i, PendingIntent.FLAG_CANCEL_CURRENT);
   am.cancel(p);
 }
Example #22
0
  /**
   * 设置午夜定时器, 午夜12点发送广播, MIDNIGHT_ALARM_FILTER. 实际测试可能会有一分钟左右的偏差.
   *
   * @param context 上下文
   */
  public static void setMidnightAlarm(Context context, String action) {
    Context appContext = context.getApplicationContext();
    Intent intent = new Intent(action);

    PendingIntent pi =
        PendingIntent.getBroadcast(appContext, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
    AlarmManager am = (AlarmManager) appContext.getSystemService(Context.ALARM_SERVICE);

    // 午夜12点的标准计时, 来源于SO, 实际测试可能会有一分钟左右的偏差.
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.HOUR, 0);
    calendar.set(Calendar.AM_PM, Calendar.AM);
    calendar.add(Calendar.DAY_OF_MONTH, 1);

    // 显示剩余时间
    long now = Calendar.getInstance().getTimeInMillis();
    Log.e("剩余时间(秒): ", ((calendar.getTimeInMillis() - now) / 1000) + "");

    // 设置之前先取消前一个PendingIntent
    am.cancel(pi);
    // 设置每一天的计时器
    am.setRepeating(
        AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pi);
  }
  @Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {

    // Hotkeys
    if (keyCode == KeyEvent.KEYCODE_BACK) {

      // If the new interval != the old interval, we got to restart the
      // "alarm"
      if (originalInterval != sharedPreferences.getInt(Constants.SP_BL_INTERVAL_SERVICE, 0)) {

        // Get the interval
        int serviceInterval =
            sharedPreferences.getInt(
                    Constants.SP_BL_INTERVAL_SERVICE, (Constants.HOUR_IN_SECONDS / 2))
                * 1000;

        // Restart the AlarmManager
        AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
        PendingIntent pendingIntent =
            PendingIntent.getService(this, 0, new Intent(this, BattlelogService.class), 0);
        alarmManager.cancel(pendingIntent);
        alarmManager.setInexactRepeating(
            AlarmManager.ELAPSED_REALTIME, 0, serviceInterval, pendingIntent);

        Log.d(
            Constants.DEBUG_TAG,
            "Setting the service to update every " + serviceInterval / 60000 + " minutes");
      }
      startActivity(new Intent(this, DashboardActivity.class));
      finish();
      return true;
    }

    return super.onKeyDown(keyCode, event);
  }
Example #24
0
  public void startService(Context context, boolean isOn, int startHour, int startMinute) {

    Intent intent = getIntent(context);

    PendingIntent pendingIntent;

    AlarmManager alarmManager = (AlarmManager) context.getSystemService(ALARM_SERVICE);

    if (isOn) {

      if (!isOnService(context)) {

        Calendar calendar = Calendar.getInstance();

        calendar.setTime(new Date());

        int nowHour = calendar.get(Calendar.HOUR_OF_DAY);

        if (nowHour < 24 && nowHour >= 10) {

          calendar.add(Calendar.DAY_OF_YEAR, 1);
        }

        calendar.set(Calendar.HOUR_OF_DAY, startHour);

        calendar.set(Calendar.MINUTE, startMinute);

        pendingIntent = PendingIntent.getService(context, 1, intent, 0);

        alarmManager.setRepeating(
            AlarmManager.RTC_WAKEUP,
            calendar.getTimeInMillis(),
            AlarmManager.INTERVAL_DAY,
            pendingIntent);

        Log.e(TAG, "service Başlatıldı");

      } else {

        Log.e(TAG, "service zaten açık");
      }

    } else {

      if (isOnService(context)) {

        pendingIntent = PendingIntent.getService(context, 1, intent, 0);

        alarmManager.cancel(pendingIntent);

        pendingIntent.cancel();

        Log.e(TAG, "service kapatıldı");

      } else {

        Log.e(TAG, "service zaten kapalı");
      }
    }
  }
  @Kroll.method
  public void cancelAlarmService(@Kroll.argument(optional = true) Object requestCode) {
    // To cancel an alarm the signature needs to be the same as the submitting one.
    utils.infoLog("Cancelling Alarm Service");
    int intentRequestCode = AlarmmanagerModule.DEFAULT_REQUEST_CODE;
    if (requestCode != null) {
      if (requestCode instanceof Number) {
        intentRequestCode = ((Number) requestCode).intValue();
      }
    }

    // Create a placeholder for the args value
    HashMap<String, Object> placeholder = new HashMap<String, Object>(0);
    KrollDict args = new KrollDict(placeholder);

    // Create the Alarm Manager
    AlarmManager am =
        (AlarmManager)
            TiApplication.getInstance()
                .getApplicationContext()
                .getSystemService(TiApplication.ALARM_SERVICE);
    Intent intent = createAlarmServiceIntent(args);
    PendingIntent sender =
        PendingIntent.getBroadcast(
            TiApplication.getInstance().getApplicationContext(),
            intentRequestCode,
            intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    am.cancel(sender);
    utils.infoLog("Alarm Service Canceled");
  }
  @Override
  public void onReceive(Context context, Intent intent) {
    alarm = (Alarm) intent.getSerializableExtra(ALARM_EXTRA);

    Intent it = new Intent(context, AlarmActivity.class);
    intent.putExtra(ALARM_EXTRA, alarm);
    PendingIntent pi =
        PendingIntent.getActivity(context, alarm.getId(), it, PendingIntent.FLAG_UPDATE_CURRENT);
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    alarmManager.cancel(pi);

    try {

      alarms = Storage.load(context);
      for (int i = 0; i < alarms.size(); i++) {
        if (alarms.get(i).getId() == alarm.getId()) {
          alarms.get(i).setEnabled(false);
          break;
        }
      }
      Storage.save(context, alarms);

    } catch (Exception e) {
      // No Exception Handling to not confuse the user :P
    }

    NotificationManager nm =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    nm.cancel(alarm.getId() + 100);
  }
Example #27
0
 private static void clearReminder(Context context) {
   Intent alarmIntent = new Intent(ReminderReceiver.REMINDER_ACTION);
   PendingIntent pendingIntent =
       PendingIntent.getBroadcast(context, 0, alarmIntent, PendingIntent.FLAG_CANCEL_CURRENT);
   AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
   alarmManager.cancel(pendingIntent);
 }
  public static void startPushService() {
    SharedPreferences preferences =
        applicationContext.getSharedPreferences("Notifications", MODE_PRIVATE);

    if (preferences.getBoolean("pushService", true)) {
      applicationContext.startService(new Intent(applicationContext, NotificationsService.class));

      if (android.os.Build.VERSION.SDK_INT >= 19) {
        //                Calendar cal = Calendar.getInstance();
        //                PendingIntent pintent = PendingIntent.getService(applicationContext, 0,
        // new Intent(applicationContext, NotificationsService.class), 0);
        //                AlarmManager alarm = (AlarmManager)
        // applicationContext.getSystemService(Context.ALARM_SERVICE);
        //                alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 30000,
        // pintent);

        PendingIntent pintent =
            PendingIntent.getService(
                applicationContext,
                0,
                new Intent(applicationContext, NotificationsService.class),
                0);
        AlarmManager alarm =
            (AlarmManager) applicationContext.getSystemService(Context.ALARM_SERVICE);
        alarm.cancel(pintent);
      }
    } else {
      stopPushService();
    }
  }
  // 2016-03-29 시청예약시 데이타베이스 처리를 programId 로 하는데 서버에서 programId를 중복으로 보내고 있다
  // 그래서 시청시간을 추가함.
  public void removeWatchTvReserveAlarmWithProgramIdAndStartTime(
      String programId, String startTime) {
    int iSeq = 0;
    Realm realm = Realm.getInstance(mContext);
    realm.beginTransaction();
    RealmResults<WatchTvObject> results =
        mRealm
            .where(WatchTvObject.class)
            .equalTo("sProgramId", programId)
            .equalTo("sProgramBroadcastingStartTime", startTime)
            .findAll();
    if (results.size() > 0) {
      WatchTvObject obj = results.get(0);
      iSeq = obj.getiSeq();
      obj.removeFromRealm();
    } else {
      //
    }
    realm.commitTransaction();

    AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(mContext, WatchTvAlarmBroadcastReceiver.class);
    PendingIntent pendingIntent =
        PendingIntent.getBroadcast(mContext, iSeq, intent, PendingIntent.FLAG_NO_CREATE);
    if (pendingIntent != null) {
      alarmManager.cancel(pendingIntent);
      pendingIntent.cancel();
    }
  }
Example #30
0
 private void stopLogicService() {
   PendingIntent pintent =
       PendingIntent.getService(
           LogicActivity.this, 0, new Intent(LogicActivity.this, LogicService.class), 0);
   AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
   alarm.cancel(pintent);
 }