List of usage examples for android.app PendingIntent FLAG_UPDATE_CURRENT
int FLAG_UPDATE_CURRENT
To view the source code for android.app PendingIntent FLAG_UPDATE_CURRENT.
Click Source Link
From source file:org.ttrssreader.utils.Utils.java
@SuppressWarnings("deprecation") public static Notification buildNotification(Context context, int icon, CharSequence ticker, CharSequence title, CharSequence text, boolean autoCancel, Intent intent) { Notification notification = null; PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); try {//w w w . jav a 2s . c o m Notification.Builder builder = new Notification.Builder(context); builder.setSmallIcon(icon); builder.setTicker(ticker); builder.setWhen(System.currentTimeMillis()); builder.setContentTitle(title); builder.setContentText(text); builder.setContentIntent(pendingIntent); builder.setAutoCancel(autoCancel); if (Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) notification = builder.getNotification(); else notification = builder.build(); } catch (Exception re) { Log.e(TAG, "Exception while building notification. Does your device propagate the right API-Level? (" + Build.VERSION.SDK_INT + ")", re); } return notification; }
From source file:co.codecrunch.musicplayerlite.manager.MusicPlayerService.java
public void setListeners(RemoteViews view) { try {/* w w w . java 2 s. c o m*/ PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(NOTIFY_PREVIOUS), PendingIntent.FLAG_UPDATE_CURRENT); view.setOnClickPendingIntent(R.id.player_previous, pendingIntent); pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(NOTIFY_CLOSE), PendingIntent.FLAG_UPDATE_CURRENT); view.setOnClickPendingIntent(R.id.player_close, pendingIntent); pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(NOTIFY_PAUSE), PendingIntent.FLAG_UPDATE_CURRENT); view.setOnClickPendingIntent(R.id.player_pause, pendingIntent); pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(NOTIFY_NEXT), PendingIntent.FLAG_UPDATE_CURRENT); view.setOnClickPendingIntent(R.id.player_next, pendingIntent); pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(NOTIFY_PLAY), PendingIntent.FLAG_UPDATE_CURRENT); view.setOnClickPendingIntent(R.id.player_play, pendingIntent); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.artech.android.gcm.GcmIntentService.java
@SuppressLint("InlinedApi") public void createNotification(String payload, String action, String notificationParameters) { NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); String appName = getString(R.string.app_name); SharedPreferences settings = MyApplication.getInstance().getAppSharedPreferences(); int notificatonID = settings.getInt("notificationID", 0); // allow multiple notifications //$NON-NLS-1$ Intent intent = new Intent("android.intent.action.MAIN"); //$NON-NLS-1$ intent.setClassName(this, getPackageName() + ".Main"); //$NON-NLS-1$ intent.addCategory("android.intent.category.LAUNCHER"); //$NON-NLS-1$ if (Services.Strings.hasValue(action)) { // call main as root of the stack with the action as intent parameter. Use clear_task like GoHome if (CompatibilityHelper.isApiLevel(Build.VERSION_CODES.HONEYCOMB)) intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); else// ww w . j av a2 s .c o m intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra(IntentParameters.NotificationAction, action); intent.putExtra(IntentParameters.NotificationParameters, notificationParameters); intent.setAction(String.valueOf(Math.random())); } else { // call main like main application shortcut intent.setFlags(0); intent.setAction("android.intent.action.MAIN"); } PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); Notification notification = NotificationHelper.newBuilder(this).setWhen(System.currentTimeMillis()) .setContentTitle(appName).setContentText(payload).setContentIntent(pendingIntent) .setStyle(new NotificationCompat.BigTextStyle().bigText(payload)) .setDefaults(Notification.DEFAULT_ALL).setAutoCancel(true).build(); notificationManager.notify(notificatonID, notification); SharedPreferences.Editor editor = settings.edit(); editor.putInt("notificationID", ++notificatonID % 32); //$NON-NLS-1$ editor.commit(); }
From source file:cn.studyjams.s2.sj0132.bowenyan.mygirlfriend.nononsenseapps.notepad.data.receiver.NotificationHelper.java
/** * Needs the builder that contains non-note specific values. * *///from w ww . ja v a 2 s .c om private static void notifyBigText(final Context context, final NotificationManager notificationManager, final NotificationCompat.Builder builder, final cn.studyjams.s2.sj0132.bowenyan.mygirlfriend.nononsenseapps.notepad.data.model.sql.Notification note) { final Intent delIntent = new Intent(Intent.ACTION_DELETE, note.getUri()); if (note.repeats != 0) { delIntent.setAction(ACTION_RESCHEDULE); } // Add extra so we don't delete all // if (note.time != null) { // delIntent.putExtra(ARG_MAX_TIME, note.time); // } delIntent.putExtra(ARG_TASKID, note.taskID); // Delete it on clear PendingIntent deleteIntent = PendingIntent.getBroadcast(context, 0, delIntent, PendingIntent.FLAG_UPDATE_CURRENT); // Open intent final Intent openIntent = new Intent(Intent.ACTION_VIEW, Task.getUri(note.taskID)); // Should create a new instance to avoid fragment problems openIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); // Delete intent on non-location repeats // Opening the note should delete/reschedule the notification openIntent.putExtra(NOTIFICATION_DELETE_ARG, note._id); // Opening always cancels the notification though openIntent.putExtra(NOTIFICATION_CANCEL_ARG, note._id); // Open note on click PendingIntent clickIntent = PendingIntent.getActivity(context, 0, openIntent, PendingIntent.FLAG_UPDATE_CURRENT); // Action to complete PendingIntent completeIntent = PendingIntent.getBroadcast(context, 0, new Intent(ACTION_COMPLETE, note.getUri()).putExtra(ARG_TASKID, note.taskID), PendingIntent.FLAG_UPDATE_CURRENT); // Action to snooze PendingIntent snoozeIntent = PendingIntent.getBroadcast(context, 0, new Intent(ACTION_SNOOZE, note.getUri()).putExtra(ARG_TASKID, note.taskID), PendingIntent.FLAG_UPDATE_CURRENT); // Build notification builder.setContentTitle(note.taskTitle).setContentText(note.taskNote).setContentIntent(clickIntent) .setStyle(new NotificationCompat.BigTextStyle().bigText(note.taskNote)); // Delete intent on non-location repeats builder.setDeleteIntent(deleteIntent); // Snooze button only on time non-repeating if (note.time != null && note.repeats == 0) { builder.addAction(R.drawable.ic_alarm_24dp_white, context.getText(R.string.snooze), snoozeIntent); } // Complete button only on non-repeating, both time and location if (note.repeats == 0) { builder.addAction(R.drawable.ic_check_24dp_white, context.getText(R.string.completed), completeIntent); } final Notification noti = builder.build(); notificationManager.notify((int) note._id, noti); }
From source file:com.binarywalllabs.sendit.managers.gcm.GcmIntentService.java
PendingIntent createShareIntent(String url) { Intent shareIntent = IntentUtils.shareText("", url); return PendingIntent.getActivity(this, 0, shareIntent, PendingIntent.FLAG_UPDATE_CURRENT); }
From source file:com.binarywalllabs.sendit.managers.gcm.GcmIntentService.java
PendingIntent createOpenIntent(String url) {
Intent shareIntent = IntentUtils.openLink(url);
return PendingIntent.getActivity(this, 0, shareIntent, PendingIntent.FLAG_UPDATE_CURRENT);
}
From source file:com.android.madpausa.cardnotificationviewer.ConcreteNotificationListenerService.java
/** * sends the service notification//from ww w . j a v a 2 s.co m */ private void handleServiceNotification() { NotificationManager nManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); //filtering archived notification list List<StatusBarNotification> filteredArchivedNotificationList = baseNotificationFilter .applyFilter(archivedNotificationMap.values(), notificationGroups, true); int filteredArchiveddSize = filteredArchivedNotificationList.size(); //should show notification only if there are notifications to be shown if (filteredArchiveddSize > 0) { NotificationCompat.Builder nBuilder = new NotificationCompat.Builder(this); nBuilder.setContentTitle( String.format(getString(R.string.service_notification_text), filteredArchiveddSize)); nBuilder.setSmallIcon(R.drawable.ic_notification); //gets the correct color resource, based on android version if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) nBuilder.setColor(getResources().getColor(R.color.app_background, null)); else //noinspection deprecation nBuilder.setColor(getResources().getColor(R.color.app_background)); //setting the intent Intent resultIntent = new Intent(this, MainActivity.class); //setting the extra containing the archived notifications resultIntent.putExtra(ARCHIVED_NOTIFICATIONS_EXTRA, new HashSet<>(archivedNotificationMap.keySet())); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); nBuilder.setContentIntent(resultPendingIntent); //low priority, not min, as it has to show in the lockscreen nBuilder.setPriority(Notification.PRIORITY_LOW); Notification notification = nBuilder.build(); //this notification should be sticky notification.flags |= Notification.FLAG_NO_CLEAR; nManager.notify(SERVICE_NOTIFICATION, 0, notification); } //else I should remove the notification else nManager.cancel(SERVICE_NOTIFICATION, 0); }
From source file:com.adarshahd.indianrailinfo.donate.PNRTracker.java
private void showNotification(String title, String contentText, ArrayList<String> inboxVal, String activityToStart) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(mContext); notificationBuilder.setSmallIcon(R.drawable.irctc).setContentTitle(title).setContentText(contentText); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); for (String str : inboxVal) { inboxStyle.addLine(str);/* w w w . j a v a 2s . c o m*/ } notificationBuilder.setStyle(inboxStyle); notificationBuilder.setOnlyAlertOnce(true); if (!activityToStart.equals("")) { Intent intent = new Intent(mContext, PNRStat.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(Presenter.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(intent); PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); notificationBuilder.setContentIntent(pendingIntent); } NotificationManager notificationManager = (NotificationManager) mContext .getSystemService(Context.NOTIFICATION_SERVICE); Notification notify = notificationBuilder.build(); //notify.sound = Uri.parse("content://settings/system/notification_sound"); notify.sound = Uri .parse(mPref.getString("notification_ringtone", "content://settings/system/notification_sound")); notify.ledARGB = 0xFF00FF00; notify.ledOffMS = 10000; notify.ledOnMS = 1500; notify.flags |= Notification.FLAG_AUTO_CANCEL; notify.flags |= Notification.FLAG_SHOW_LIGHTS; if (mPref.getBoolean("notification_vibrate", true)) { //Should find out a way to vibrate long[] pattern = { 0, 200 }; notify.vibrate = pattern; } /*notify.flags = Notification.DEFAULT_ALL; notify.flags |= Notification.FLAG_ONLY_ALERT_ONCE; notify.flags |= Notification.DEFAULT_SOUND; notify.flags |= Notification.DEFAULT_LIGHTS;*/ notificationManager.notify(0, notify); }
From source file:com.binarywalllabs.sendit.managers.gcm.GcmIntentService.java
PendingIntent createCopyToClipboardIntent(String message) { Intent clipboardIntent = CopyToClipboard.createIntent(this, message, message); return PendingIntent.getService(this, 0, clipboardIntent, PendingIntent.FLAG_UPDATE_CURRENT); }
From source file:com.perm.DoomPlay.PlayingService.java
private Notification createOldNotif() { NotificationCompat.Builder builder = new NotificationCompat.Builder(this); Intent intentActivity;/* w ww .j a va 2 s . co m*/ if (SettingActivity.getPreferences(SettingActivity.keyOnClickNotif)) { intentActivity = new Intent(FullPlaybackActivity.actionReturnFull); intentActivity.setClass(this, FullPlaybackActivity.class); intentActivity.putExtra(FileSystemActivity.keyMusic, audios); } else { intentActivity = FullPlaybackActivity.getReturnSmallIntent(this, audios); } intentActivity.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); builder.setContentIntent( PendingIntent.getActivity(this, 0, intentActivity, PendingIntent.FLAG_UPDATE_CURRENT)) .setOngoing(true) .setSmallIcon(isPlaying ? R.drawable.status_icon_pause : R.drawable.status_icon_play); Audio audio = audios.get(indexCurrentTrack); builder.setContentTitle(audio.getTitle()); builder.setContentText(audio.getArtist()); Bitmap cover = AlbumArtGetter.getBitmapFromStore(audio.getAid(), this); if (cover == null) { Bitmap tempBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.fallback_cover); builder.setLargeIcon(tempBitmap); tempBitmap.recycle(); } else { builder.setLargeIcon(cover); cover.recycle(); } return builder.build(); }