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.ubergeek42.WeechatAndroid.service.Notificator.java
@AnyThread @Cat/*from w ww .j a va 2 s. c om*/ static void showMain(@NonNull RelayService relay, @NonNull String content) { PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(context, WeechatActivity.class), PendingIntent.FLAG_CANCEL_CURRENT); boolean authenticated = relay.state.contains(AUTHENTICATED); int icon = authenticated ? R.drawable.ic_connected : R.drawable.ic_disconnected; Builder builder = new Builder(context, NOTIFICATION_CHANNEL_CONNECTION_STATUS); builder.setContentIntent(contentIntent).setSmallIcon(icon) .setContentTitle("Weechat-Android " + BuildConfig.VERSION_NAME).setContentText(content) .setWhen(System.currentTimeMillis()); builder.setPriority(Notification.PRIORITY_MIN); if (P.notificationTicker) builder.setTicker(content); String disconnectText = context.getString(authenticated ? R.string.disconnect : R.string.stop_connecting); builder.addAction(android.R.drawable.ic_menu_close_clear_cancel, disconnectText, PendingIntent.getService( context, 0, new Intent(RelayService.ACTION_STOP, null, context, RelayService.class), 0)); Notification notification = builder.build(); notification.flags |= Notification.FLAG_ONGOING_EVENT; relay.startForeground(NOTIFICATION_MAIN_ID, notification); }
From source file:com.perm.DoomPlay.DownloadNotifBuilder.java
private Notification createStartingNew() { Notification notification = new Notification(); RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.notif_download); views.setProgressBar(R.id.progressDownload, 100, 0, true); views.setTextViewText(R.id.notifTitle, context.getResources().getString(R.string.Downloading)); views.setTextViewText(R.id.notifArtist, track.getArtist() + "-" + track.getTitle()); views.setImageViewResource(R.id.notifPause, R.drawable.widget_pause); ComponentName componentName = new ComponentName(context, DownloadingService.class); Intent intentClose = new Intent(PlayingService.actionClose); intentClose.putExtra("aid", track.getAid()); intentClose.setComponent(componentName); Intent intentPause = new Intent(PlayingService.actionIconPause); intentPause.putExtra("aid", track.getAid()); intentPause.setComponent(componentName); views.setOnClickPendingIntent(R.id.notifClose, PendingIntent.getService(context, notificationId, intentClose, PendingIntent.FLAG_UPDATE_CURRENT)); views.setOnClickPendingIntent(R.id.notifPause, PendingIntent.getService(context, notificationId, intentPause, PendingIntent.FLAG_UPDATE_CURRENT)); notification.contentView = views;/*w w w . j a va2s .c o m*/ notification.flags = Notification.FLAG_ONGOING_EVENT; notification.icon = R.drawable.download_icon; return notification; }
From source file:com.joulespersecond.seattlebusbot.tripservice.NotifierTask.java
private void notify(Cursor c) { final int id = c.getInt(COL_ID); final String tripId = c.getString(COL_TRIP_ID); final String stopId = c.getString(COL_STOP_ID); final int state = c.getInt(COL_STATE); if (state == TripAlerts.STATE_CANCELLED) { return;/*from w ww . java2 s . c o m*/ } final Uri tripUri = ObaContract.Trips.buildUri(tripId, stopId); final String routeId = UIHelp.stringForQuery(mContext, tripUri, Trips.ROUTE_ID); // Set our state to notified Notification notification = mTaskContext.getNotification(id); // #104 - Instantiate the deleteIntent here, since we need to re-set it in setLatestInfo() Intent deleteIntent = new Intent(mContext, TripService.class); deleteIntent.setAction(TripService.ACTION_CANCEL); deleteIntent.setData(mUri); PendingIntent pendingIntent = PendingIntent.getService(mContext, 0, deleteIntent, PendingIntent.FLAG_UPDATE_CURRENT); if (notification == null) { notification = createNotification(pendingIntent); } setLatestInfo(notification, stopId, routeId, mTimeDiff, pendingIntent); mTaskContext.setNotification(id, notification); }
From source file:com.example.android.background.utilities.NotificationUtils.java
private static Action drinkWaterAction(Context context) { Intent incrementWaterCountIntent = new Intent(context, WaterReminderIntentService.class); incrementWaterCountIntent.setAction(ReminderTasks.ACTION_INCREMENT_WATER_COUNT); PendingIntent incrementWaterPendingIntent = PendingIntent.getService(context, ACTION_DRINK_PENDING_INTENT_ID, incrementWaterCountIntent, PendingIntent.FLAG_CANCEL_CURRENT); Action drinkWaterAction = new Action(R.drawable.ic_local_drink_black_24px, "I did it!", incrementWaterPendingIntent); return drinkWaterAction; }
From source file:com.androidinspain.deskclock.alarms.AlarmNotifications.java
static synchronized void showLowPriorityNotification(Context context, AlarmInstance instance) { LogUtils.v("Displaying low priority notification for alarm instance: " + instance.mId); NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setShowWhen(false) .setContentTitle(/*from w w w . ja v a 2 s . c o m*/ context.getString(com.androidinspain.deskclock.R.string.alarm_alert_predismiss_title)) .setContentText(AlarmUtils.getAlarmText(context, instance, true /* includeLabel */)) .setColor(ContextCompat.getColor(context, com.androidinspain.deskclock.R.color.default_background)) .setSmallIcon(com.androidinspain.deskclock.R.drawable.stat_notify_alarm).setAutoCancel(false) .setSortKey(createSortKey(instance)).setPriority(NotificationCompat.PRIORITY_DEFAULT) .setCategory(NotificationCompat.CATEGORY_ALARM).setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setLocalOnly(true); if (Utils.isNOrLater()) { builder.setGroup(UPCOMING_GROUP_KEY); } // Setup up hide notification Intent hideIntent = AlarmStateManager.createStateChangeIntent(context, AlarmStateManager.ALARM_DELETE_TAG, instance, AlarmInstance.HIDE_NOTIFICATION_STATE); final int id = instance.hashCode(); builder.setDeleteIntent( PendingIntent.getService(context, id, hideIntent, PendingIntent.FLAG_UPDATE_CURRENT)); // Setup up dismiss action Intent dismissIntent = AlarmStateManager.createStateChangeIntent(context, AlarmStateManager.ALARM_DISMISS_TAG, instance, AlarmInstance.PREDISMISSED_STATE); builder.addAction(com.androidinspain.deskclock.R.drawable.ic_alarm_off_24dp, context.getString(com.androidinspain.deskclock.R.string.alarm_alert_dismiss_text), PendingIntent.getService(context, id, dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT)); // Setup content action if instance is owned by alarm Intent viewAlarmIntent = createViewAlarmIntent(context, instance); builder.setContentIntent( PendingIntent.getActivity(context, id, viewAlarmIntent, PendingIntent.FLAG_UPDATE_CURRENT)); NotificationManagerCompat nm = NotificationManagerCompat.from(context); final Notification notification = builder.build(); nm.notify(id, notification); updateUpcomingAlarmGroupNotification(context, -1, notification); }
From source file:com.example.android.elizachat.ResponderService.java
private void showNotification() { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "Sent: " + mLastResponse); }// w ww . j a v a 2s . c o m NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setContentTitle(getString(R.string.eliza)).setContentText(mLastResponse) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.bg_eliza)) .setSmallIcon(R.drawable.bg_eliza).setPriority(NotificationCompat.PRIORITY_MIN); Intent intent = new Intent(ACTION_RESPONSE); PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT); Notification notification = builder.extend(new NotificationCompat.WearableExtender() .addAction(new NotificationCompat.Action.Builder(R.drawable.ic_full_reply, getString(R.string.reply), pendingIntent).addRemoteInput( new RemoteInput.Builder(EXTRA_REPLY).setLabel(getString(R.string.reply)).build()) .build())) .build(); NotificationManagerCompat.from(this).notify(0, notification); }
From source file:com.twentyoneechoes.borges.util.Utils.java
public static void scheduleLibraryUpdateService(Context context) { if (isAlarmAlreadySet(context)) return;//from w ww. jav a 2 s. co m AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, LibraryUpdateService.class); PendingIntent alarmIntent = PendingIntent.getService(context, LIBRARY_UPDATE_REQUEST_CODE, intent, 0); alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, AlarmManager.INTERVAL_HALF_HOUR, AlarmManager.INTERVAL_HALF_HOUR, alarmIntent); }
From source file:com.android.deskclock.alarms.AlarmNotifications.java
public static void showHighPriorityNotification(Context context, AlarmInstance instance) { LogUtils.v("Displaying high priority notification for alarm instance: " + instance.mId); NotificationCompat.Builder notification = new NotificationCompat.Builder(context) .setContentTitle(context.getString(R.string.alarm_alert_predismiss_title)) .setContentText(AlarmUtils.getAlarmText(context, instance, true /* includeLabel */)) .setSmallIcon(R.drawable.stat_notify_alarm).setAutoCancel(false).setOngoing(true) .setGroup(Integer.toString(instance.hashCode())).setGroupSummary(true) .setPriority(NotificationCompat.PRIORITY_HIGH).setCategory(NotificationCompat.CATEGORY_ALARM) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC).setLocalOnly(true); // Setup up dismiss action Intent dismissIntent = AlarmStateManager.createStateChangeIntent(context, AlarmStateManager.ALARM_DISMISS_TAG, instance, AlarmInstance.PREDISMISSED_STATE); notification.addAction(R.drawable.ic_alarm_off_24dp, context.getString(R.string.alarm_alert_dismiss_now_text), PendingIntent.getService(context, instance.hashCode(), dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT)); // Setup content action if instance is owned by alarm Intent viewAlarmIntent = createViewAlarmIntent(context, instance); notification.setContentIntent(PendingIntent.getActivity(context, instance.hashCode(), viewAlarmIntent, PendingIntent.FLAG_UPDATE_CURRENT)); NotificationManagerCompat nm = NotificationManagerCompat.from(context); nm.notify(instance.hashCode(), notification.build()); }
From source file:com.cyanogenmod.account.util.CMAccountUtils.java
public static void scheduleCMAccountPing(Context context, Intent intent) { if (CMAccount.DEBUG) Log.d(TAG,//from w w w .j a v a 2s . c o m "Scheduling CMAccount ping, starting = " + new Timestamp(SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_DAY) + " interval (" + AlarmManager.INTERVAL_DAY + ")"); PendingIntent reRegisterPendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_DAY, AlarmManager.INTERVAL_DAY, reRegisterPendingIntent); }
From source file:com.example.android.wearable.elizachat.ResponderService.java
private void showNotification() { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "Sent: " + mLastResponse); }/* w w w.j a v a 2 s . c om*/ NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setContentTitle(getString(R.string.eliza)).setContentText(mLastResponse) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.bg_eliza)) .setSmallIcon(R.drawable.bg_eliza).setPriority(NotificationCompat.PRIORITY_DEFAULT); Intent intent = new Intent(ACTION_RESPONSE); PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT); Notification notification = builder.extend(new NotificationCompat.WearableExtender() .addAction(new NotificationCompat.Action.Builder(R.drawable.ic_full_reply, getString(R.string.reply), pendingIntent).addRemoteInput( new RemoteInput.Builder(EXTRA_REPLY).setLabel(getString(R.string.reply)).build()) .build())) .build(); NotificationManagerCompat.from(this).notify(0, notification); }