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.ntsync.android.sync.syncadapter.SyncAdapter.java
private void sendMissingKey(Account account, final String authToken, byte[] saltPwdCheck) { Intent intent = KeyPasswordActivity.createKeyPasswortActivity(mContext, account, authToken, saltPwdCheck); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent resultPendingIntent = PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext) .setSmallIcon(R.drawable.notif_key) .setContentTitle(String.format(mContext.getText(R.string.notif_missing_key).toString())) .setContentText(account.name).setAutoCancel(false).setOnlyAlertOnce(true) .setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) mContext .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(account.name, Constants.NOTIF_MISSING_KEY, mBuilder.build()); }
From source file:com.android.dragonkeyboardfirmwareupdater.KeyboardFirmwareUpdateService.java
private void showUpdateNotification() { Log.d(TAG, "showUpdateNotification: " + getKeyboardString()); // Intent for triggering the update confirmation page. Intent updateConfirmation = new Intent(this, UpdateConfirmationActivity.class); updateConfirmation.putExtra(EXTRA_KEYBOARD_NAME, mKeyboardName); updateConfirmation.putExtra(EXTRA_KEYBOARD_ADDRESS, mKeyboardAddress); updateConfirmation.putExtra(EXTRA_KEYBOARD_FIRMWARE_VERSION, mKeyboardFirmwareVersion); updateConfirmation.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // Intent for postponing update. Intent postponeUpdate = new Intent(ACTION_KEYBOARD_UPDATE_POSTPONED); // Wrap intents into pending intents for notification use. PendingIntent laterIntent = PendingIntent.getBroadcast(this, 0, postponeUpdate, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent installIntent = PendingIntent.getActivity(this, 0, updateConfirmation, PendingIntent.FLAG_CANCEL_CURRENT); // Create a notification object with two buttons (actions) mUpdateNotification = new NotificationCompat.Builder(this).setCategory(Notification.CATEGORY_SYSTEM) .setContentTitle(getString(R.string.notification_update_title)) .setContentText(getString(R.string.notification_update_text)).setSmallIcon(R.drawable.ic_keyboard) .addAction(new NotificationCompat.Action.Builder(R.drawable.ic_later, getString(R.string.notification_update_later), laterIntent).build()) .addAction(new NotificationCompat.Action.Builder(R.drawable.ic_install, getString(R.string.notification_update_install), installIntent).build()) .setAutoCancel(true).setOnlyAlertOnce(true).build(); // Show the notification via notification manager NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(UPDATE_NOTIFICATION_ID, mUpdateNotification); }
From source file:com.heightechllc.breakify.MainActivity.java
/** * Cancels the alarm scheduled by startTimer() *//*from w w w. j a v a2s . c o m*/ private void cancelScheduledAlarm() { // Cancel the AlarmManager PendingIntent pendingIntent = PendingIntent.getBroadcast(this, ALARM_MANAGER_REQUEST_CODE, new Intent(this, AlarmReceiver.class), PendingIntent.FLAG_UPDATE_CURRENT); alarmManager.cancel(pendingIntent); // Hide the persistent notification AlarmNotifications.hideNotification(this); // Remove record of when the timer will ring sharedPref.edit().remove("schedRingTime").apply(); }
From source file:com.android.deskclock.data.TimerModel.java
/** * Updates the heads-up notification controlling expired timers. This heads-up notification is * displayed whether the application is open or not. *//* w w w . ja v a 2 s.com*/ private void updateHeadsUpNotification() { // Nothing can be done with the heads-up notification without a valid service reference. if (mService == null) { return; } final List<Timer> expired = getExpiredTimers(); // If no expired timers exist, stop the service (which cancels the foreground notification). if (expired.isEmpty()) { mService.stopSelf(); mService = null; return; } // Generate some descriptive text, a title, and an action name based on the timer count. final int timerId; final String contentText; final String contentTitle; final String resetActionTitle; if (expired.size() > 1) { timerId = -1; contentText = mContext.getString(R.string.timer_multi_times_up, expired.size()); contentTitle = mContext.getString(R.string.timer_notification_label); resetActionTitle = mContext.getString(R.string.timer_stop_all); } else { final Timer timer = expired.get(0); timerId = timer.getId(); resetActionTitle = mContext.getString(R.string.timer_stop); contentText = mContext.getString(R.string.timer_times_up); final String label = timer.getLabel(); if (TextUtils.isEmpty(label)) { contentTitle = mContext.getString(R.string.timer_notification_label); } else { contentTitle = label; } } // Content intent shows the timer full screen when clicked. final Intent content = new Intent(mContext, ExpiredTimersActivity.class); final PendingIntent pendingContent = PendingIntent.getActivity(mContext, 0, content, PendingIntent.FLAG_UPDATE_CURRENT); // Full screen intent has flags so it is different than the content intent. final Intent fullScreen = new Intent(mContext, ExpiredTimersActivity.class) .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION); final PendingIntent pendingFullScreen = PendingIntent.getActivity(mContext, 0, fullScreen, PendingIntent.FLAG_UPDATE_CURRENT); // First action intent is either reset single timer or reset all timers. final Intent reset = TimerService.createResetExpiredTimersIntent(mContext); final PendingIntent pendingReset = PendingIntent.getService(mContext, 0, reset, PendingIntent.FLAG_UPDATE_CURRENT); final NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext).setWhen(0) .setOngoing(true).setLocalOnly(true).setAutoCancel(false).setContentText(contentText) .setContentTitle(contentTitle).setContentIntent(pendingContent) .setSmallIcon(R.drawable.stat_notify_timer).setFullScreenIntent(pendingFullScreen, true) .setPriority(NotificationCompat.PRIORITY_MAX).setDefaults(NotificationCompat.DEFAULT_LIGHTS) .addAction(R.drawable.ic_stop_24dp, resetActionTitle, pendingReset); // Add a second action if only a single timer is expired. if (expired.size() == 1) { // Second action intent adds a minute to a single timer. final Intent addMinute = TimerService.createAddMinuteTimerIntent(mContext, timerId); final PendingIntent pendingAddMinute = PendingIntent.getService(mContext, 0, addMinute, PendingIntent.FLAG_UPDATE_CURRENT); final String addMinuteTitle = mContext.getString(R.string.timer_plus_1_min); builder.addAction(R.drawable.ic_add_24dp, addMinuteTitle, pendingAddMinute); } // Update the notification. final Notification notification = builder.build(); final int notificationId = mNotificationModel.getExpiredTimerNotificationId(); mService.startForeground(notificationId, notification); }
From source file:org.wso2.iot.agent.utils.CommonUtils.java
public static void displayNotification(Context context, int icon, String title, String message, Class<?> sourceActivityClass, String tag, int id) { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context); mBuilder.setSmallIcon(icon);// w ww.j ava 2 s . c o m mBuilder.setContentTitle(title); mBuilder.setContentText(message); mBuilder.setOngoing(true); mBuilder.setOnlyAlertOnce(true); Intent resultIntent = new Intent(context, sourceActivityClass); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(sourceActivityClass); // 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) context .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(tag, id, mBuilder.build()); }
From source file:com.ntsync.android.sync.syncadapter.SyncAdapter.java
private void notifyUserPhotoNotSynced(String accountName) { Account account = new Account(accountName, Constants.ACCOUNT_TYPE); AccountManager acm = AccountManager.get(mContext); String synced = acm.getUserData(account, NOTIF_SHOWN_PHOTO_SYNCED); if (synced == null) { Intent shopIntent = new Intent(mContext, ShopActivity.class); shopIntent.putExtra(ShopActivity.PARM_ACCOUNT_NAME, accountName); TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext); stackBuilder.addParentStack(ShopActivity.class); stackBuilder.addNextIntent(shopIntent); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext) .setSmallIcon(Constants.NOTIF_ICON) .setContentTitle(getText(R.string.notif_photonotsynced_title)).setContentText(accountName) .setAutoCancel(true)/*from w w w .ja va 2s. c om*/ .setContentIntent(stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT)) .setOnlyAlertOnce(true); NotificationManager mNotificationManager = (NotificationManager) mContext .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(Constants.NOTIF_PHOTO_NOT_SYNCED, mBuilder.build()); acm.setUserData(account, NOTIF_SHOWN_PHOTO_SYNCED, String.valueOf(System.currentTimeMillis())); } }
From source file:com.ntsync.android.sync.syncadapter.SyncAdapter.java
private void notifyUserConctactNotSynced(int maxCount, int totalLocalContacts, String accountName) { AccountManager acm = AccountManager.get(mContext); Account account = new Account(accountName, Constants.ACCOUNT_TYPE); String lastTimeShown = acm.getUserData(account, NOTIF_SHOWN_CONTACTS_SYNCED); Long lastTime;//from w ww . jav a2 s . c o m try { lastTime = lastTimeShown != null ? Long.parseLong(lastTimeShown) : null; } catch (NumberFormatException ex) { LogHelper.logWCause(TAG, "Invalid Config-Settings:" + NOTIF_SHOWN_CONTACTS_SYNCED + " Value:" + lastTimeShown, ex); lastTime = null; } if (lastTime == null || System.currentTimeMillis() > lastTime.longValue() + NOTIF_WAIT_TIME) { // Create Shop-Intent Intent shopIntent = new Intent(mContext, ShopActivity.class); shopIntent.putExtra(ShopActivity.PARM_ACCOUNT_NAME, account.name); // Adds the back stack TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext); stackBuilder.addParentStack(ShopActivity.class); stackBuilder.addNextIntent(shopIntent); // Create Notification NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext) .setSmallIcon(Constants.NOTIF_ICON) .setContentTitle(String.format(getText(R.string.notif_contactnotsynced_title), maxCount, totalLocalContacts)) .setContentText(String.format(getText(R.string.notif_contactnotsynced_content), account.name)) .setAutoCancel(true).setOnlyAlertOnce(true) .setContentIntent(stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT)); NotificationManager mNotificationManager = (NotificationManager) mContext .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(Constants.NOTIF_CONTACTS_NOT_SYNCED, mBuilder.build()); acm.setUserData(account, NOTIF_SHOWN_CONTACTS_SYNCED, String.valueOf(System.currentTimeMillis())); } }
From source file:com.dwdesign.tweetings.service.TweetingsService.java
private Notification buildNotification(final String title, final String message, final int icon, final Intent content_intent, final Intent delete_intent) { final NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setTicker(message);//w ww. ja v a 2 s.c om builder.setContentTitle(title); builder.setContentText(message); builder.setAutoCancel(true); builder.setWhen(System.currentTimeMillis()); builder.setSmallIcon(icon); if (delete_intent != null) { builder.setDeleteIntent( PendingIntent.getBroadcast(this, 0, delete_intent, PendingIntent.FLAG_UPDATE_CURRENT)); } if (content_intent != null) { builder.setContentIntent( PendingIntent.getActivity(this, 0, content_intent, PendingIntent.FLAG_UPDATE_CURRENT)); } int defaults = 0; final Calendar now = Calendar.getInstance(); if (mPreferences.getBoolean(PREFERENCE_KEY_NOTIFICATION_HAVE_SOUND, true) && !mPreferences.getBoolean("silent_notifications_at_" + now.get(Calendar.HOUR_OF_DAY), false)) { Uri soundUri = Uri.parse(mPreferences.getString(PREFERENCE_KEY_NOTIFICATION_RINGTONE, "android.resource://" + getPackageName() + "/" + R.raw.notify)); builder.setSound(soundUri, Notification.STREAM_DEFAULT); } if (mPreferences.getBoolean(PREFERENCE_KEY_NOTIFICATION_HAVE_VIBRATION, true) && !mPreferences.getBoolean("silent_notifications_at_" + now.get(Calendar.HOUR_OF_DAY), false)) { defaults |= Notification.DEFAULT_VIBRATE; } if (mPreferences.getBoolean(PREFERENCE_KEY_NOTIFICATION_HAVE_LIGHTS, true) && !mPreferences.getBoolean("silent_notifications_at_" + now.get(Calendar.HOUR_OF_DAY), false)) { final int color_def = getResources().getColor(R.color.holo_blue_dark); final int color = mPreferences.getInt(PREFERENCE_KEY_NOTIFICATION_LIGHT_COLOR, color_def); builder.setLights(color, 1000, 2000); } builder.setDefaults(defaults); return builder.getNotification(); }
From source file:de.ub0r.android.websms.connector.common.Utils.java
/** * Show update notification.// w w w . ja v a 2s. c o m * * @param context * {@link Context} * @param pkg * package */ public static void showUpdateNotification(final Context context, final String pkg) { Notification n = new Notification(android.R.drawable.stat_sys_warning, context.getString(R.string.update_title), 0); n.flags = Notification.FLAG_AUTO_CANCEL; PendingIntent pi = PendingIntent.getActivity(context, 0, new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + pkg)), PendingIntent.FLAG_UPDATE_CURRENT); n.setLatestEventInfo(context, context.getString(R.string.update_title), context.getString(R.string.update_message), pi); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(0, n); }