List of usage examples for android.app PendingIntent getBroadcast
public static PendingIntent getBroadcast(Context context, int requestCode, Intent intent, @Flags int flags)
From source file:MainActivity.java
public void cancelAlarm() { Intent intentToFire = new Intent(getApplicationContext(), AlarmBroadcastReceiver.class); intentToFire.setAction(AlarmBroadcastReceiver.ACTION_ALARM); PendingIntent alarmIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, intentToFire, 0); AlarmManager alarmManager = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE); alarmManager.cancel(alarmIntent);//w ww . j av a2 s . c o m }
From source file:com.alchemiasoft.book.receiver.SuggestionReceiver.java
/** * Schedule a suggestion alarm.//from ww w. j a va 2s . c o m * * @param context reference. * @return true if the alarm has been successfully scheduled, false otherwise. */ public static boolean scheduleSuggestion(Context context) { final AlarmManager alarmManager = AlarmUtil.getAlarmManager(context); if (sPendingIntent != null) { alarmManager.cancel(sPendingIntent); } final UserData userData = UserData.load(context); final UserData.SuggestionInterval interval = userData.suggestionInterval(); if (interval == UserData.SuggestionInterval.NEVER) { return false; } final Intent intent = new Intent(SUGGESTION_ACTION); sPendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); final long refreshInMills = interval.seconds() * DateUtils.SECOND_IN_MILLIS; Log.d(TAG_LOG, "AlarmReceiver: scheduling suggestion in " + interval.seconds() + " sec(s)."); alarmManager.set(AlarmManager.RTC, System.currentTimeMillis() + refreshInMills, sPendingIntent); return true; }
From source file:com.commonsware.android.job.PollReceiver.java
static void cancelAlarm(Context ctxt, AlarmManager alarms) { Intent i = new Intent(ctxt, PollReceiver.class); PendingIntent pi = PendingIntent.getBroadcast(ctxt, 0, i, 0); alarms.cancel(pi);//from ww w . j a v a2s . c o m }
From source file:com.ivarprudnikov.sensors.OnBootBroadcastReceiver.java
@Override public void onReceive(Context context, Intent intent) { AlarmManager mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); // Starts service responsible for sensor data storage Intent startSensorDataServiceIntent = new Intent(context, OnAlarmBroadcastReceiver.class); startSensorDataServiceIntent.setAction(Constants.INTENT_ACTION_TRIGGER_FROM_BOOT); PendingIntent pi1 = PendingIntent.getBroadcast(context, 0, startSensorDataServiceIntent, 0); mgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + START_AT_OFFSET, pi1); // Registers alarms required for data export Intent startDataExportIntent = new Intent(context, OnExportAlarmBroadcastReceiver.class); startDataExportIntent.setAction(Constants.INTENT_ACTION_TRIGGER_FROM_BOOT); PendingIntent pi2 = PendingIntent.getBroadcast(context, 0, startSensorDataServiceIntent, 0); mgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + START_AT_OFFSET, pi2); }
From source file:com.byteshaft.neon.Notification.java
private void setOnTapIntentAction(NotificationCompat.Builder builder) { Intent intent = new Intent("com.byteshaft.neon.CLOSE_ACTIVITY"); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0); builder.setContentIntent(pendingIntent); }
From source file:at.florian_lentsch.expirysync.NotifyChecker.java
/** * Sets the alarm that checks for products soon to expire (or already have * expired)/*from w w w .j a v a 2 s .c o m*/ * * @param context */ protected static void setAlarm(Context context) { Context appContext = context.getApplicationContext(); Intent receiverIntent = new Intent(appContext, NotifyChecker.class); // Fetch info about when the alarm is to sound each day from the shared // preferences: long firstStartMillis = getFirstStartMillis(appContext); if (firstStartMillis < 0) { Log.i("Alarm", "Alert time not configured - not setting alarm"); return; } Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(firstStartMillis); // Log.i("Alarm", "Setting alarm: " + firstStartMillis + ", " + (new // SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", // Locale.US)).format(firstStartMillis)); // Set the alarm: PendingIntent alarmIntent = PendingIntent.getBroadcast(appContext, 0, receiverIntent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager alarmMgr = (AlarmManager) appContext.getSystemService(Context.ALARM_SERVICE); alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, firstStartMillis, AlarmManager.INTERVAL_DAY, alarmIntent); }
From source file:com.commonsware.android.deepbg.PollReceiver.java
static void scheduleInexactAlarm(Context ctxt, AlarmManager alarms, long period, boolean isDownload) { Intent i = buildBaseIntent(ctxt).putExtra(EXTRA_IS_DOWNLOAD, isDownload); PendingIntent pi = PendingIntent.getBroadcast(ctxt, 0, i, 0); alarms.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + period, period, pi);/*from w w w. j a v a 2 s. c o m*/ }
From source file:com.example.stacky.ScheduledMaintenanceService.java
@Override public void onCreate() { super.onCreate(); alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); // Setup the pending action to fire when the alarm fires Intent intentToFire = new Intent(ScheduledMaintenanceReceiver.ACTION_SCHEDULED_MAINTENANCE_ALARM); startAlarmPendingIntent = PendingIntent.getBroadcast(this, PENDING_REQUEST_CODE, intentToFire, 0); }
From source file:com.doctoror.fuckoffmusicplayer.data.media.session.MediaSessionFactoryImpl.java
public MediaSessionFactoryImpl(@NonNull final Context context, @NonNull final Class<? extends Activity> sessionActivityClass, @NonNull final MediaSessionCompat.Callback mediaSessionCallback) { this.context = context; this.sessionActivityClass = sessionActivityClass; this.mediaSessionCallback = mediaSessionCallback; this.mediaButtonReceiver = new ComponentName(context, MediaButtonReceiver.class); this.mediaButtonIntent = PendingIntent.getBroadcast(context, 1, new Intent(context, MediaButtonReceiver.class), PendingIntent.FLAG_UPDATE_CURRENT); }
From source file:cat.wuyingren.whatsannoy.utils.SystemUtils.java
public static void cancelAlarm(Context context, Schedule schedule) { Intent intent = new Intent(context, Alarm.class); PendingIntent pi = PendingIntent.getBroadcast(context, SystemUtils.safeLongToInt(schedule.getId()), intent, 0);/*from ww w. j a v a2 s . c o m*/ AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmMgr.cancel(pi); }