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:com.chen.mail.utils.NotificationActionUtils.java
/** * Creates a {@link PendingIntent} for the specified notification action. *//*from www. j av a 2s. c o m*/ private static PendingIntent getNotificationActionPendingIntent(final Context context, final Account account, final Conversation conversation, final Message message, final Folder folder, final Intent notificationIntent, final NotificationActionType action, final int notificationId, final long when) { final Uri messageUri = message.uri; final NotificationAction notificationAction = new NotificationAction(action, account, conversation, message, folder, conversation.id, message.serverId, message.id, when); switch (action) { case REPLY: { // Build a task stack that forces the conversation view on the stack before the // reply activity. final TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context); final Intent intent = createReplyIntent(context, account, messageUri, false); intent.setPackage(context.getPackageName()); intent.putExtra(ComposeActivity.EXTRA_NOTIFICATION_FOLDER, folder); // To make sure that the reply intents one notification don't clobber over // intents for other notification, force a data uri on the intent final Uri notificationUri = Uri.parse("mailfrom://mail/account/" + "reply/" + notificationId); intent.setData(notificationUri); taskStackBuilder.addNextIntent(notificationIntent).addNextIntent(intent); return taskStackBuilder.getPendingIntent(notificationId, PendingIntent.FLAG_UPDATE_CURRENT); } case REPLY_ALL: { // Build a task stack that forces the conversation view on the stack before the // reply activity. final TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context); final Intent intent = createReplyIntent(context, account, messageUri, true); intent.setPackage(context.getPackageName()); intent.putExtra(ComposeActivity.EXTRA_NOTIFICATION_FOLDER, folder); // To make sure that the reply intents one notification don't clobber over // intents for other notification, force a data uri on the intent final Uri notificationUri = Uri.parse("mailfrom://mail/account/" + "replyall/" + notificationId); intent.setData(notificationUri); taskStackBuilder.addNextIntent(notificationIntent).addNextIntent(intent); return taskStackBuilder.getPendingIntent(notificationId, PendingIntent.FLAG_UPDATE_CURRENT); } case ARCHIVE_REMOVE_LABEL: { final String intentAction = NotificationActionIntentService.ACTION_ARCHIVE_REMOVE_LABEL; final Intent intent = new Intent(intentAction); intent.setPackage(context.getPackageName()); putNotificationActionExtra(intent, notificationAction); return PendingIntent.getService(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT); } case DELETE: { final String intentAction = NotificationActionIntentService.ACTION_DELETE; final Intent intent = new Intent(intentAction); intent.setPackage(context.getPackageName()); putNotificationActionExtra(intent, notificationAction); return PendingIntent.getService(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT); } } throw new IllegalArgumentException("Invalid NotificationActionType"); }
From source file:com.android.talkback.TalkBackUpdateHelper.java
private Notification buildGestureChangeNotification(Intent clickIntent) { final PendingIntent pendingIntent = PendingIntent.getActivity(mService, 0, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT); final String ticker = mService.getString(R.string.notification_title_talkback_gestures_changed); final String contentTitle = mService.getString(R.string.notification_title_talkback_gestures_changed); final String contentText = mService.getString(R.string.notification_message_talkback_gestures_changed); final Notification notification = new NotificationCompat.Builder(mService) .setSmallIcon(R.drawable.ic_stat_info).setTicker(ticker).setContentTitle(contentTitle) .setContentText(contentText).setContentIntent(pendingIntent).setAutoCancel(false).setWhen(0) .build();/*from w w w.jav a 2s . c om*/ notification.defaults |= Notification.DEFAULT_SOUND; notification.flags |= Notification.FLAG_ONGOING_EVENT; return notification; }
From source file:com.android.tv.tuner.setup.TunerSetupActivity.java
/** * Returns a {@link PendingIntent} to launch the tuner TV input service. * * @param context a {@link Context} instance *//*from ww w .ja v a 2s.c o m*/ private static PendingIntent createPendingIntentForSetupActivity(Context context) { return PendingIntent.getActivity(context, 0, createSetupActivity(context), PendingIntent.FLAG_UPDATE_CURRENT); }
From source file:tcc.iesgo.activity.ClientMapActivity.java
@Override protected void onPause() { super.onPause(); PendingIntent origPendingIntent = PendingIntent.getBroadcast(getBaseContext(), 0, getIntent(), PendingIntent.FLAG_UPDATE_CURRENT); lm.removeUpdates(origPendingIntent); }
From source file:com.brayanarias.alarmproject.activity.AlarmScreenActivity.java
private void sendNotification(String msg) { alarmNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); String title = getString(R.string.title_activity_main); Intent intent = new Intent(this, AlarmScreenActivity.class); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); Bitmap bitmap = ((BitmapDrawable) getResources().getDrawable(R.mipmap.ic_launcher)).getBitmap(); NotificationCompat.Builder alarmNotificationBuilder = new NotificationCompat.Builder(this) .setContentTitle(title).setSmallIcon(R.drawable.ic_fab_alarm).setLargeIcon(bitmap) .setCategory(Notification.CATEGORY_ALARM) .setColor(ContextCompat.getColor(getBaseContext(), R.color.colorAccent)) .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg).setOngoing(true) .setContentIntent(pendingIntent); alarmNotificationManager.notify(1503, alarmNotificationBuilder.build()); }
From source file:pt.up.mobile.syncadapter.SigarraSyncAdapter.java
private void syncNotifications(Account account, SyncResult syncResult) throws AuthenticationException, IOException { final User user = AccountUtils.getUser(getContext(), account.name); final String notificationReply = SifeupAPI.getReply(SifeupAPI.getNotificationsUrl(user.getUserCode()), account, getContext());//w w w .j a v a 2 s.co m final Gson gson = GsonUtils.getGson(); final Notification[] notifications = gson.fromJson(notificationReply, Notification[].class); if (notifications == null) { syncResult.stats.numParseExceptions++; LogUtils.trackException(getContext(), new RuntimeException(), notificationReply, true); return; } ArrayList<String> fetchedNotCodes = new ArrayList<String>(); ArrayList<ContentValues> bulkValues = new ArrayList<ContentValues>(); for (Notification not : notifications) { final ContentValues values = new ContentValues(); values.put(SigarraContract.Notifcations.CONTENT, gson.toJson(not)); fetchedNotCodes.add(not.getCode()); if (getContext().getContentResolver().update(SigarraContract.Notifcations.CONTENT_URI, values, SigarraContract.Notifcations.UPDATE_NOTIFICATION, SigarraContract.Notifcations.getNotificationsSelectionArgs(account.name, not.getCode())) == 0) { values.put(SigarraContract.Notifcations.CODE, account.name); values.put(SigarraContract.Notifcations.ID_NOTIFICATION, not.getCode()); values.put(SigarraContract.Notifcations.STATE, SigarraContract.Notifcations.NEW); values.put(SigarraContract.Notifcations.CODE, account.name); bulkValues.add(values); } } // inserting the values if (bulkValues.size() > 0) { getContext().getContentResolver().bulkInsert(SigarraContract.Notifcations.CONTENT_URI, bulkValues.toArray(new ContentValues[0])); // if the account being synced is the current active accout // display notification if (AccountUtils.getActiveUserName(getContext()).equals(account.name)) { final NotificationManager mNotificationManager = (NotificationManager) getContext() .getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builder notBuilder = new NotificationCompat.Builder(getContext()); notBuilder.setAutoCancel(true).setOnlyAlertOnce(true) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); if (bulkValues.size() == 1) { final Notification notification = gson.fromJson( bulkValues.get(0).getAsString(SigarraContract.Notifcations.CONTENT), Notification.class); Intent notifyIntent = new Intent(getContext(), NotificationsDescActivity.class) .putExtra(NotificationsDescFragment.NOTIFICATION, notification); // Creates the PendingIntent PendingIntent notifyPendingIntent = PendingIntent.getActivity(getContext(), 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT); // Sets the Activity to start in a new, empty task notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); notBuilder.setSmallIcon(R.drawable.icon).setTicker(notification.getMessage()) .setContentTitle(notification.getSubject()).setContentText(notification.getMessage()) .setContentIntent(notifyPendingIntent) .setStyle(new NotificationCompat.BigTextStyle().bigText(notification.getMessage()) .setBigContentTitle(notification.getSubject()) .setSummaryText(notification.getMessage())); mNotificationManager.notify(notification.getCode().hashCode(), notBuilder.build()); } else { final String notTitle = getContext().getString(R.string.new_notifications, bulkValues.size()); Intent notifyIntent = new Intent(getContext(), NotificationsActivity.class); // Sets the Activity to start in a new, empty task notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); // Creates the PendingIntent PendingIntent notifyPendingIntent = PendingIntent.getActivity(getContext(), 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); // Sets a title for the Inbox style big view inboxStyle.setBigContentTitle(notTitle); // Moves events into the big view for (ContentValues value : bulkValues) { final Notification notification = gson.fromJson( value.getAsString(SigarraContract.Notifcations.CONTENT), Notification.class); inboxStyle.addLine(notification.getSubject()); } // Moves the big view style object into the notification // object. notBuilder.setStyle(inboxStyle); notBuilder.setSmallIcon(R.drawable.icon).setTicker(notTitle).setContentTitle(notTitle) .setContentText("").setContentIntent(notifyPendingIntent); mNotificationManager.notify(NotificationsFragment.class.getName().hashCode(), notBuilder.build()); } } } final Cursor syncState = getContext().getContentResolver().query(SigarraContract.LastSync.CONTENT_URI, SigarraContract.LastSync.COLUMNS, SigarraContract.LastSync.PROFILE, SigarraContract.LastSync.getLastSyncSelectionArgs(AccountUtils.getActiveUserName(getContext())), null); try { if (syncState.moveToFirst()) { if (syncState.getLong(syncState.getColumnIndex(SigarraContract.LastSync.NOTIFICATIONS)) == 0) { // Report that we have checked the notifications final ContentValues values = new ContentValues(); values.put(SigarraContract.LastSync.NOTIFICATIONS, System.currentTimeMillis()); getContext().getContentResolver().update(SigarraContract.LastSync.CONTENT_URI, values, SigarraContract.LastSync.PROFILE, SigarraContract.LastSync.getLastSyncSelectionArgs(account.name)); } } } finally { syncState.close(); } ArrayList<String> notToDelete = new ArrayList<String>(); final Cursor cursor = getContext().getContentResolver().query(SigarraContract.Notifcations.CONTENT_URI, new String[] { SigarraContract.Notifcations.ID_NOTIFICATION }, SigarraContract.Notifcations.PROFILE, SigarraContract.Notifcations.getNotificationsSelectionArgs(account.name), null); try { if (cursor.moveToFirst()) { do { final String code = cursor.getString(0); if (!fetchedNotCodes.contains(code)) notToDelete.add(code); } while (cursor.moveToNext()); } else { // no notifications getContext().getContentResolver().notifyChange(SigarraContract.Notifcations.CONTENT_URI, null); } } finally { cursor.close(); } if (notToDelete.size() > 0) getContext().getContentResolver().delete(SigarraContract.Notifcations.CONTENT_URI, SigarraContract.Notifcations.getNotificationsDelete(notToDelete.toArray(new String[0])), SigarraContract.Notifcations.getNotificationsSelectionArgs(account.name, notToDelete.toArray(new String[0]))); syncResult.stats.numEntries += notifications.length; }
From source file:com.ithinkbest.taipeiok.NavigationDrawerActivity.java
private void notifyGooglePlay() { int idGooglePlay = 12345; NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher).setContentTitle(getString(R.string.app_name)) .setContentText(getString(R.string.to_google_play)); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(this, ToGooglePlayActivity.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(ToGooglePlayActivity.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); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. mNotificationManager.notify(idGooglePlay, mBuilder.build()); }
From source file:no.firestorm.weathernotificatonservice.WeatherNotificationService.java
/** * Set alarm/*from w ww . j a v a2s . c om*/ * * @param updateRate * in minutes */ private void setAlarm(long updateRate) { // Set alarm final PendingIntent pendingIntent = PendingIntent.getService(this, 0, new Intent(this, WeatherNotificationService.class), PendingIntent.FLAG_UPDATE_CURRENT); final AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE); // Set time to next hour plus 5 minutes: final long now = System.currentTimeMillis(); long triggerAtTime = now; // set back to last hour plus 2 minutes: triggerAtTime -= triggerAtTime % 3600000 - 12000; // Add selected update rate triggerAtTime += updateRate * 60000; // Check that trigger time is not passed. if (triggerAtTime < now) triggerAtTime = now + updateRate * 60000; alarm.set(AlarmManager.RTC, triggerAtTime, pendingIntent); }
From source file:tcc.iesgo.activity.ClientMapActivity.java
@Override protected void onStop() { super.onStop(); PendingIntent origPendingIntent = PendingIntent.getBroadcast(getBaseContext(), 0, getIntent(), PendingIntent.FLAG_UPDATE_CURRENT); lm.removeUpdates(origPendingIntent); //System.exit(0); }
From source file:com.androidinspain.deskclock.alarms.AlarmNotifications.java
static synchronized void showSnoozeNotification(Context context, AlarmInstance instance) { LogUtils.v("Displaying snoozed notification for alarm instance: " + instance.mId); NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setShowWhen(false) .setContentTitle(instance.getLabelOrDefault(context)) .setContentText(context.getString(com.androidinspain.deskclock.R.string.alarm_alert_snooze_until, AlarmUtils.getFormattedTime(context, instance.getAlarmTime()))) .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_MAX) .setCategory(NotificationCompat.CATEGORY_ALARM).setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setLocalOnly(true);//from w w w. j a v a2 s . c om if (Utils.isNOrLater()) { builder.setGroup(UPCOMING_GROUP_KEY); } // Setup up dismiss action Intent dismissIntent = AlarmStateManager.createStateChangeIntent(context, AlarmStateManager.ALARM_DISMISS_TAG, instance, AlarmInstance.DISMISSED_STATE); final int id = instance.hashCode(); 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); }