List of usage examples for android.app PendingIntent getService
public static PendingIntent getService(Context context, int requestCode, @NonNull Intent intent, @Flags int flags)
From source file:com.phonemetra.account.util.AccountUtils.java
public static void scheduleRetry(Context context, SharedPreferences prefs, Intent intent) { int backoffTimeMs = getBackoff(prefs); int nextAttempt = backoffTimeMs / 2 + sRandom.nextInt(backoffTimeMs); if (Account.DEBUG) Log.d(TAG, "Scheduling retry, backoff = " + nextAttempt + " (" + backoffTimeMs + ") for " + intent.getAction());/*from w w w .j av a2s . c om*/ PendingIntent retryPendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); am.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + nextAttempt, retryPendingIntent); if (backoffTimeMs < Account.MAX_BACKOFF_MS) { setBackoff(prefs, backoffTimeMs * 2); } }
From source file:com.hodor.company.areminder.service.TimerService.java
private void removeAlarm() { NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.cancel(1);//from w w w .ja v a 2s. c o m AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(MainActivity.ACTION_SHOW_ALARM, null, this, TimerService.class); PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); alarmManager.cancel(pendingIntent); }
From source file:cn.apputest.ctria.service.UploadFailRecordService.java
public static void setServiceAlarm(Context context) { Log.i("ServiceUtil-AlarmManager", "invokeTimerPOIService wac called.."); PendingIntent alarmSender = null;//from w w w . j a va2 s . c o m Intent startIntent = new Intent(context, UploadFailRecordService.class); startIntent.setAction(Constants.POI_SERVICE_ACTION); try { alarmSender = PendingIntent.getService(context, 0, startIntent, PendingIntent.FLAG_UPDATE_CURRENT); } catch (Exception e) { Log.i("ServiceUtil-AlarmManager", "failed to start " + e.toString()); } AlarmManager am = (AlarmManager) context.getSystemService(Activity.ALARM_SERVICE); am.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), Constants.ELAPSED_TIME_F, alarmSender); }
From source file:edu.mit.media.realityanalysis.fieldtest.MainPipeline.java
@Override public void onCreate() { super.onCreate(); String password = getDataPassword(this); // If the user hasn't logged in yet, we need to stop the service // NOTE: this currently doesn't work properly because we're just using the default password (changeme) if (password == null || password == "") { Intent loginIntent = new Intent(this, LoginActivity.class); startActivity(loginIntent);//from ww w . j av a 2s.c o m this.stopSelf(); } else { setEncryptionPassword(getDataPassword(this).toCharArray()); } //Setup the notification service to run periodically Intent notificationIntent = new Intent(this, NotificationService.class); PendingIntent notificationPendingIntent = PendingIntent.getService(this, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), AlarmManager.INTERVAL_HALF_HOUR, notificationPendingIntent); }
From source file:com.example.android.background.utilities.NotificationUtils.java
private static Action ignoreReminderAction(Context context) { Intent ignoreReminderIntent = new Intent(context, WaterReminderIntentService.class); ignoreReminderIntent.setAction(ReminderTasks.ACTION_DISMISS_NOTIFICATION); PendingIntent ignoreReminderPendingIntent = PendingIntent.getService(context, ACTION_IGNORE_PENDING_INTENT_ID, ignoreReminderIntent, PendingIntent.FLAG_UPDATE_CURRENT); Action ignoreReminderAction = new Action(R.drawable.ic_cancel_black_24px, "No, thanks.", ignoreReminderPendingIntent); return ignoreReminderAction; }
From source file:ch.fixme.status.Widget.java
protected static void setAlarm(Context ctxt, Intent i, int widgetId, int delay) { // Get interval SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctxt); long update_interval = Long .parseLong(prefs.getString(Prefs.KEY_CHECK_INTERVAL, Prefs.DEFAULT_CHECK_INTERVAL)) * 60L * 1000L; // Set alarm//from w w w. j a va2 s. com AlarmManager am = (AlarmManager) ctxt.getSystemService(Context.ALARM_SERVICE); PendingIntent pi = PendingIntent.getService(ctxt, widgetId, i, 0); am.cancel(pi); am.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + delay, update_interval, pi); // Log.i(Main.TAG, "start notification every " + update_interval / 1000 // + "s"); }
From source file:com.example.android.pingme.PingService.java
private void issueNotification(Intent intent, String msg) { mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // Sets up the Snooze and Dismiss action buttons that will appear in the // expanded view of the notification. Intent dismissIntent = new Intent(this, PingService.class); dismissIntent.setAction(CommonConstants.ACTION_DISMISS); PendingIntent piDismiss = PendingIntent.getService(this, 0, dismissIntent, 0); Intent snoozeIntent = new Intent(this, PingService.class); snoozeIntent.setAction(CommonConstants.ACTION_SNOOZE); PendingIntent piSnooze = PendingIntent.getService(this, 0, snoozeIntent, 0); // Constructs the Builder object. builder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_stat_notification) .setContentTitle(getString(R.string.notification)).setContentText(getString(R.string.ping)) .setDefaults(Notification.DEFAULT_ALL) // requires VIBRATE permission /*/* w ww . jav a 2 s . c o m*/ * Sets the big view "big text" style and supplies the * text (the user's reminder message) that will be displayed * in the detail area of the expanded notification. * These calls are ignored by the support library for * pre-4.1 devices. */ .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)) .addAction(R.drawable.ic_stat_dismiss, getString(R.string.dismiss), piDismiss) .addAction(R.drawable.ic_stat_snooze, getString(R.string.snooze), piSnooze); /* * Clicking the notification itself displays ResultActivity, which provides * UI for snoozing or dismissing the notification. * This is available through either the normal view or big view. */ Intent resultIntent = new Intent(this, ResultActivity.class); resultIntent.putExtra(CommonConstants.EXTRA_MESSAGE, msg); resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); // Because clicking the notification opens a new ("special") activity, there's // no need to create an artificial back stack. PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(resultPendingIntent); startTimer(mMillis); }
From source file:de.badaix.snapcast.SnapclientService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { if (intent == null) return START_NOT_STICKY; if (intent.getAction() == ACTION_STOP) { stopService();/*from w w w .j a v a 2s .co m*/ return START_NOT_STICKY; } else if (intent.getAction() == ACTION_START) { String host = intent.getStringExtra(EXTRA_HOST); int port = intent.getIntExtra(EXTRA_PORT, 1704); Intent stopIntent = new Intent(this, SnapclientService.class); stopIntent.setAction(ACTION_STOP); PendingIntent piStop = PendingIntent.getService(this, 0, stopIntent, 0); NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_media_play).setTicker(getText(R.string.ticker_text)) .setContentTitle(getText(R.string.notification_title)) .setContentText(getText(R.string.notification_text)).setContentInfo(host) .setStyle(new NotificationCompat.BigTextStyle().bigText(getText(R.string.notification_text))) .addAction(R.drawable.ic_media_stop, getString(R.string.stop), piStop); Intent resultIntent = new Intent(this, MainActivity.class); // The stack builder object will contain an artificial back stack for the // started Activity. // This ensures that navigating backward from the Activity leads out of // your application to the Home screen. TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(MainActivity.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. final Notification notification = builder.build(); // mNotificationManager.notify(123, notification); startForeground(123, notification); start(host, port); return START_STICKY; } return START_NOT_STICKY; }
From source file:com.nextgis.maplibui.service.RebuildCacheService.java
@Override public void onCreate() { mNotifyManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Bitmap largeIcon = NotificationHelper.getLargeIcon(R.drawable.ic_notification_rebuild_cache, getResources());/*from w w w . j ava 2 s .c om*/ mProgressIntent = new Intent(ACTION_UPDATE); Intent intent = new Intent(this, RebuildCacheService.class); intent.setAction(ACTION_STOP); PendingIntent stopService = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); intent.setAction(ACTION_SHOW); PendingIntent showProgressDialog = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder = new NotificationCompat.Builder(this); mBuilder.setSmallIcon(R.drawable.ic_notification_rebuild_cache).setLargeIcon(largeIcon).setAutoCancel(false) .setOngoing(true).setContentIntent(showProgressDialog) .addAction(R.drawable.ic_action_cancel_dark, getString(android.R.string.cancel), stopService); mQueue = new LinkedList<>(); }
From source file:alaindc.memenguage.RandomIntentService.java
private void setTimeout() { // Set the alarms for next sensing of amplitude alarmMgr = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE); Intent intentAlarm = new Intent(getApplicationContext(), RandomIntentService.class); intentAlarm.setAction(Constants.ACTION_RANDOM_WORD); alarmIntent = PendingIntent.getService(getApplicationContext(), 0, intentAlarm, 0); try {// www . j a v a 2 s . co m // Remove the oldest one if exists alarmMgr.cancel(alarmIntent); } catch (Exception e) { Log.d("Randomintentservice", "Cancel pending intent error"); } long millisec = Long.parseLong( PreferenceManager.getDefaultSharedPreferences(this).getString("interval_notifications", "120")) * 60 * 1000; alarmMgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + millisec, alarmIntent); }