PendingIntent pendingIntent = PendingIntent.getBroadcast(context,notId, intent, 0); pendingIntent.cancel();
am = (AlarmManager) getSystemService(getApplicationContext().ALARM_SERVICE); Intent i = new Intent(getApplicationContext(),AlarmReceiver.class); PendingIntent p = PendingIntent.getBroadcast(getApplicationContext(), 0, i, 0); am.cancel(p); p.cancel();
public static void cancel(@NonNull Context context, int jobId, @Nullable PendingIntent pendingIntent) { try { if (pendingIntent == null) { Intent intent = PlatformAlarmServiceExact.createIntent(context, jobId, null); pendingIntent = PendingIntent.getService(context, jobId, intent, PendingIntent.FLAG_NO_CREATE); if (pendingIntent == null) { return; } } AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmManager.cancel(pendingIntent); pendingIntent.cancel(); } catch (Exception e) { CAT.e(e); // we don't care if it fails, we don't want to crash the library } } }
private void deleteAlarm(Intent i, int requestCode) { if (doesPendingIntentExist(i, requestCode)) { PendingIntent pi = PendingIntent.getService(getContext(), requestCode, i, PendingIntent.FLAG_NO_CREATE); pi.cancel(); getAlarmManager().cancel(pi); Log.d("OskarSchindler", "PI Cancelled " + doesPendingIntentExist(i, requestCode)); } }
@Test public void cancel_shouldRemovePendingIntentForActivity() { Intent intent = new Intent(); PendingIntent pendingIntent = PendingIntent.getActivity(context, 99, intent, 100); assertThat(pendingIntent).isNotNull(); pendingIntent.cancel(); assertThat(PendingIntent.getActivity(context, 99, intent, FLAG_NO_CREATE)).isNull(); }
@Test public void cancel_shouldRemovePendingIntentForBroadcast() { Intent intent = new Intent(); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 99, intent, 100); assertThat(pendingIntent).isNotNull(); pendingIntent.cancel(); assertThat(PendingIntent.getBroadcast(context, 99, intent, FLAG_NO_CREATE)).isNull(); }
@Test public void cancel_shouldRemovePendingIntentForService() { Intent intent = new Intent(); PendingIntent pendingIntent = PendingIntent.getService(context, 99, intent, 100); assertThat(pendingIntent).isNotNull(); pendingIntent.cancel(); assertThat(PendingIntent.getService(context, 99, intent, FLAG_NO_CREATE)).isNull(); }
@Test public void cancel_shouldRemovePendingIntentForActivities() { Intent[] intents = {new Intent(Intent.ACTION_VIEW), new Intent(Intent.ACTION_PICK)}; PendingIntent pendingIntent = PendingIntent.getActivities(context, 99, intents, 100); assertThat(pendingIntent).isNotNull(); pendingIntent.cancel(); assertThat(PendingIntent.getActivities(context, 99, intents, FLAG_NO_CREATE)).isNull(); }
@Test @Config(minSdk = Build.VERSION_CODES.O) public void cancel_shouldRemovePendingIntentForForegroundService() { Intent intent = new Intent(); PendingIntent pendingIntent = PendingIntent.getForegroundService(context, 99, intent, 100); assertThat(pendingIntent).isNotNull(); pendingIntent.cancel(); assertThat(PendingIntent.getForegroundService(context, 99, intent, FLAG_NO_CREATE)).isNull(); }
PendingIntent pendingIntent = PendingIntent.getService(this, 50000, intent, PendingIntent.FLAG_NO_CREATE); //Cancelling the PendingIntent in the AlarmManager If it is already exist if(pendingIntent != null) { am.cancel(pendingIntent); pendingIntent.cancel(); }
Intent alarmIntent = new Intent(MainActivity.this, AlarmReceiver.class); final PendingIntent pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, alarmIntent, PendingIntent.FLAG_NO_CREATE); if (pendingIntent != null) { pendingIntent.cancel(); }
public Boolean cancelAlarm(int id) { Intent myIntent = new Intent(context, AlarmMiddle.class); PendingIntent pending_intent = PendingIntent.getBroadcast(context, id, myIntent, PendingIntent.FLAG_NO_CREATE); if (pending_intent != null) { alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); alarmManager.cancel(pending_intent); pending_intent.cancel(); } return false; }
Intent intent1 = new Intent(G.context, DailyAlarmReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(G.context, G.dateTimesetAlarm.getDayOfYear(), intent1, 0); mAlarmManager.cancel(pendingIntent); pendingIntent.cancel();
Intent intentlocal = new Intent(SampledateActivity.this,AlarmReceiver.class); PendingIntent pilocal = PendingIntent.getBroadcast(SampledateActivity.this, uniqueno, intentlocal, 0); AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); alarmManager.cancel(pilocal); pilocal.cancel();
public void clearAlarm() { if(alarmManager != null && updateIntent != null) { updateIntent.cancel(); alarmManager.cancel(updateIntent); } }
public void cancelAlarm(Context context, String type) { AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, AlarmReceiver.class); int requestCode = type.equalsIgnoreCase(TYPE_ONE_TIME) ? ID_ONETIME : ID_REPEATING; PendingIntent pendingIntent = PendingIntent.getBroadcast(context, requestCode, intent, 0); pendingIntent.cancel(); if (alarmManager != null) { alarmManager.cancel(pendingIntent); } Toast.makeText(context, "Repeating alarm dibatalkan", Toast.LENGTH_SHORT).show(); }
Intent intent = new Intent(this, MyReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), eventId, intent, 0); AlarmManager am = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE); am.cancel(pendingIntent); // Cancel the `PendingIntent` after you've canceled the alarm pendingIntent.cancel();
Intent DataSyncing = new Intent(getBaseContext(), DataSyncingScheduledReceiver.class); DataSyncing.setAction(DataSyncingScheduledReceiver.ACTION_DATASYNC_RECEIVER); PendingIntent DataSyncingIntent = PendingIntent.getBroadcast(getBaseContext(),1003, DataSyncing, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager alarmManagerdatasync = (AlarmManager) getSystemService(ALARM_SERVICE); alarmManagerdatasync.cancel(DataSyncingIntent); DataSyncingIntent.cancel();
public void cancelAlarm() { AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); alarmManager.cancel(getPendingIntent(mCls)); getPendingIntent(mCls).cancel(); }
private void stopBtService() { Log.d(TAG, "stopService call stopService"); CollectionServiceStarter.stopBtService(getApplicationContext()); Log.d(TAG, "stopBtService should have called onDestroy"); AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); PendingIntent wakeIntent = PendingIntent.getService(this, 0, new Intent(this, Notifications.class), PendingIntent.FLAG_UPDATE_CURRENT); wakeIntent.cancel(); alarmManager.cancel(wakeIntent); Log.d(TAG, "stopBtService cancel Notifications wakeIntent"); }