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:anastasoft.rallyvision.activity.MenuPrincipal.java
private void createNotification() { Intent resultIntent = new Intent(this, MenuPrincipal.class); // 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); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_notify).setContentTitle(getString(R.string.notification_title)) .setContentText(getString(R.string.notification_text)).setContentInfo(getString(R.string.app_name)) .setAutoCancel(true).setOngoing(true).setTicker(getString(R.string.notification_ticker)); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // mId allows you to setState the notification later on. Notification notification = mBuilder.build(); mNotificationManager.notify(NOTIFICATION_ID, notification); }
From source file:com.ibm.mobilefirstplatform.clientsdk.android.push.api.MFPPushIntentService.java
private void generateNotification(Context context, String ticker, String title, String msg, int icon, Intent intent, String sound, int notificationId, MFPInternalPushMessage message) { int androidSDKVersion = Build.VERSION.SDK_INT; long when = System.currentTimeMillis(); Notification notification = null; NotificationCompat.Builder builder = new NotificationCompat.Builder(this); if (message.getGcmStyle() != null && androidSDKVersion > 21) { NotificationCompat.Builder mBuilder = null; NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); try {//from w w w . ja va 2 s .c o m JSONObject gcmStyleObject = new JSONObject(message.getGcmStyle()); String type = gcmStyleObject.getString(TYPE); if (type != null && type.equalsIgnoreCase(PICTURE_NOTIFICATION)) { Bitmap remote_picture = null; NotificationCompat.BigPictureStyle notificationStyle = new NotificationCompat.BigPictureStyle(); notificationStyle.setBigContentTitle(ticker); notificationStyle.setSummaryText(gcmStyleObject.getString(TITLE)); try { remote_picture = new getBitMapBigPictureNotification() .execute(gcmStyleObject.getString(URL)).get(); } catch (Exception e) { logger.error( "MFPPushIntentService:generateNotification() - Error while fetching image file."); } if (remote_picture != null) { notificationStyle.bigPicture(remote_picture); } mBuilder = new NotificationCompat.Builder(context); notification = mBuilder.setSmallIcon(icon).setLargeIcon(remote_picture).setAutoCancel(true) .setContentTitle(title) .setContentIntent(PendingIntent.getActivity(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT)) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) .setContentText(msg).setStyle(notificationStyle).build(); } else if (type != null && type.equalsIgnoreCase(BIGTEXT_NOTIFICATION)) { NotificationCompat.BigTextStyle notificationStyle = new NotificationCompat.BigTextStyle(); notificationStyle.setBigContentTitle(ticker); notificationStyle.setSummaryText(gcmStyleObject.getString(TITLE)); notificationStyle.bigText(gcmStyleObject.getString(TEXT)); mBuilder = new NotificationCompat.Builder(context); notification = mBuilder.setSmallIcon(icon).setAutoCancel(true).setContentTitle(title) .setContentIntent(PendingIntent.getActivity(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT)) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) .setContentText(msg).setStyle(notificationStyle).build(); } else if (type != null && type.equalsIgnoreCase(INBOX_NOTIFICATION)) { NotificationCompat.InboxStyle notificationStyle = new NotificationCompat.InboxStyle(); notificationStyle.setBigContentTitle(ticker); notificationStyle.setSummaryText(gcmStyleObject.getString(TITLE)); String lines = gcmStyleObject.getString(LINES).replaceAll("\\[", "").replaceAll("\\]", ""); String[] lineArray = lines.split(","); for (String line : lineArray) { notificationStyle.addLine(line); } mBuilder = new NotificationCompat.Builder(context); notification = mBuilder.setSmallIcon(icon).setAutoCancel(true).setContentTitle(title) .setContentIntent(PendingIntent.getActivity(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT)) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) .setContentText(msg).setStyle(notificationStyle).build(); } notification.flags = Notification.FLAG_AUTO_CANCEL; notificationManager.notify(notificationId, notification); } catch (JSONException e) { logger.error("MFPPushIntentService:generateNotification() - Error while parsing JSON."); } } else { if (androidSDKVersion > 10) { builder.setContentIntent(PendingIntent.getActivity(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT)).setSmallIcon(icon).setTicker(ticker).setWhen(when) .setAutoCancel(true).setContentTitle(title).setContentText(msg) .setSound(getNotificationSoundUri(context, sound)); if (androidSDKVersion > 15) { int priority = getPriorityOfMessage(message); builder.setPriority(priority); notification = builder.build(); } if (androidSDKVersion > 19) { //As new material theme is very light, the icon is not shown clearly //hence setting the background of icon to black builder.setColor(Color.BLACK); Boolean isBridgeSet = message.getBridge(); if (!isBridgeSet) { // show notification only on current device. builder.setLocalOnly(true); } notification = builder.build(); int receivedVisibility = 1; String visibility = message.getVisibility(); if (visibility != null && visibility.equalsIgnoreCase(MFPPushConstants.VISIBILITY_PRIVATE)) { receivedVisibility = 0; } if (receivedVisibility == Notification.VISIBILITY_PRIVATE && message.getRedact() != null) { builder.setContentIntent(PendingIntent.getActivity(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT)).setSmallIcon(icon).setTicker(ticker) .setWhen(when).setAutoCancel(true).setContentTitle(title) .setContentText(message.getRedact()) .setSound(getNotificationSoundUri(context, sound)); notification.publicVersion = builder.build(); } } if (androidSDKVersion > 21) { String setPriority = message.getPriority(); if (setPriority != null && setPriority.equalsIgnoreCase(MFPPushConstants.PRIORITY_MAX)) { //heads-up notification builder.setContentText(msg).setFullScreenIntent(PendingIntent.getActivity(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT), true); notification = builder.build(); } } } else { notification = builder .setContentIntent( PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)) .setSmallIcon(icon).setTicker(ticker).setWhen(when).setAutoCancel(true) .setContentTitle(title).setContentText(msg) .setSound(getNotificationSoundUri(context, sound)).build(); } NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(notificationId, notification); } }
From source file:com.firescar96.nom.GCMIntentService.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private static void Notify(String notificationTitle, String notificationMessage, Bundle data, int id, boolean annoy) { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(thisService) .setSmallIcon(R.drawable.ic_launcher).setContentTitle(notificationTitle) .setContentText(notificationMessage).setAutoCancel(true); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(thisService, MainActivity.class); resultIntent.putExtras(data);/*from w w w . j a v a 2 s . co m*/ // 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(thisService); // 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); mBuilder.setContentIntent(resultPendingIntent); if (annoy) { Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); mBuilder.setSound(alarmSound); long[] pattern = { 50, 100, 10, 100, 10, 200 }; mBuilder.setVibrate(pattern); } NotificationManager mNotificationManager = (NotificationManager) thisService .getSystemService(Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. mNotificationManager.notify(id, mBuilder.build()); }
From source file:com.android.deskclock.alarms.AlarmStateManager.java
/** * Used in L and later devices where "next alarm" is stored in the Alarm Manager. *///from w ww. ja va 2 s. c o m @TargetApi(Build.VERSION_CODES.LOLLIPOP) private static void updateNextAlarmInAlarmManager(Context context, AlarmInstance nextAlarm) { // Sets a surrogate alarm with alarm manager that provides the AlarmClockInfo for the // alarm that is going to fire next. The operation is constructed such that it is ignored // by AlarmStateManager. AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); int flags = nextAlarm == null ? PendingIntent.FLAG_NO_CREATE : 0; PendingIntent operation = PendingIntent.getBroadcast(context, 0 /* requestCode */, AlarmStateManager.createIndicatorIntent(context), flags); if (nextAlarm != null) { long alarmTime = nextAlarm.getAlarmTime().getTimeInMillis(); // Create an intent that can be used to show or edit details of the next alarm. PendingIntent viewIntent = PendingIntent.getActivity(context, nextAlarm.hashCode(), AlarmNotifications.createViewAlarmIntent(context, nextAlarm), PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager.AlarmClockInfo info = new AlarmManager.AlarmClockInfo(alarmTime, viewIntent); alarmManager.setAlarmClock(info, operation); } else if (operation != null) { alarmManager.cancel(operation); } }
From source file:com.android.settings.cyanogenmod.LtoService.java
private PendingIntent scheduleNextDownload(long lastDownload) { AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(this, LtoService.class); PendingIntent pi = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT); long nextLtoDownload = lastDownload + LongTermOrbits.getDownloadInterval(); am.set(AlarmManager.RTC, nextLtoDownload, pi); return pi;/*from w w w . ja v a2 s . c om*/ }
From source file:com.strathclyde.highlightingkeyboard.SoftKeyboardService.java
/** * Main initialization of the input method component. * Set up the word separators list//from w w w.j a v a 2 s.co m * Initialize the core service * Initialize the colours to be used in highlighting * Initialize the list of autocorrected words * Load the suspect-replacement probability distribution map */ @Override public void onCreate() { super.onCreate(); //get User ID try { Class<?> c = Class.forName("android.os.SystemProperties"); Method get = c.getMethod("get", String.class); userid = (String) get.invoke(c, "ro.serialno"); Log.i("OnCreate", "User id= " + userid); } catch (Exception ignored) { Log.i("OnCreate", "Could not obtain userid"); userid = "xxx"; } Editor e = PreferenceManager.getDefaultSharedPreferences(this).edit(); e.putString("prefUsername", userid); e.commit(); //used for managing injected errors errorMap = new HashMap<Integer, Character>(); mWordSeparators = getResources().getString(R.string.word_separators); mSpecialSeparators = getResources().getString(R.string.special_separators); CoreEngineInitialize.initializeCoreService(getApplicationContext()); initializeCore(); assignColours(); autocorrected_words = new HashMap<String, String>(); try { suspectReplacementDistribution = new JSONObject(loadJSONFromAsset()); } catch (JSONException ex) { // TODO Auto-generated catch block ex.printStackTrace(); } //setup the upload task alarm manager /* * Twice daily, broadcast an event * This will be trapped by our receiver */ Intent alarmIntent = new Intent(this, UploadDataReceiver.class); alarmIntent.putExtra("origin", "alarm"); alarmIntent.putExtra("insert", true); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); alarmManager.setInexactRepeating(AlarmManager.RTC, Calendar.getInstance().getTimeInMillis(), AlarmManager.INTERVAL_HALF_DAY, pendingIntent); //Log.i("OnCreate", "Alarm set "); }
From source file:com.bcp.bcp.geofencing.GeofenceTransitionsIntentService.java
/** * Posts a notification in the notification bar when a transition is detected. * If the user clicks the notification, control goes to the MainActivity. *//*from w w w .j a va 2s.c o m*/ private void sendNotification(String notificationDetails) { // Create an explicit content Intent that starts the main Activity. Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class); // Construct a task stack. TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Add the main Activity to the task stack as the parent. stackBuilder.addParentStack(MainActivity.class); // Push the content Intent onto the stack. stackBuilder.addNextIntent(notificationIntent); // Get a PendingIntent containing the entire back stack. PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Get a notification builder that's compatible with platform versions >= 4 NotificationCompat.Builder builder = new NotificationCompat.Builder(this); // Define the notification settings. builder.setSmallIcon(R.mipmap.ic_launcher) // In a real app, you may want to use a library like Volley // to decode the Bitmap. .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)) .setColor(Color.RED).setContentTitle(notificationDetails) .setContentText(getString(R.string.geofence_transition_notification_text)) .setContentIntent(notificationPendingIntent); // Dismiss notification once the user touches it. builder.setAutoCancel(true); // Get an instance of the Notification manager NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // Issue the notification mNotificationManager.notify(0, builder.build()); }
From source file:com.teinproductions.tein.papyrosprogress.UpdateCheckReceiver.java
private static void issueBlogNotification(Context context) { String title = context.getString(R.string.notification_title); String message = context.getString(R.string.blog_notification_content); PendingIntent pendingIntent;/* ww w.j ava2 s .c om*/ try { pendingIntent = PendingIntent.getActivity(context, 0, new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.PAPYROS_BLOG_URL)), PendingIntent.FLAG_UPDATE_CURRENT); } catch (Exception e) { e.printStackTrace(); return; } NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setContentTitle(title) .setContentText(message).setContentIntent(pendingIntent) .setSmallIcon(R.mipmap.notification_small_icon) .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher)) .setDefaults(Notification.DEFAULT_ALL).setAutoCancel(true); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(BLOG_NOTIFICATION_ID, builder.build()); }
From source file:com.careme.apvereda.careme.AccumulatorService.java
private void shownot(String s) { Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_notifications); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext()) .setSmallIcon(R.mipmap.ic_notsmall).setLargeIcon(bitmap).setContentTitle("Cuidado!") .setContentText(s).setVibrate(new long[] { 100, 250, 100, 500 }); Intent resultIntent = new Intent(getApplicationContext(), MainActivity.class); PendingIntent resultPendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); int mNotificationId = 001; NotificationManager mNotifyMgr = (NotificationManager) getApplicationContext() .getSystemService(Context.NOTIFICATION_SERVICE); mNotifyMgr.notify(mNotificationId, mBuilder.build()); }
From source file:at.flack.receiver.FacebookReceiver.java
@Override public void onReceive(Context context, Intent intent) { Bundle bundle = intent.getExtras();//w ww . j a va 2s. c o m try { if (main instanceof FbMessageOverview && bundle.getString("type").equals("message")) { ((FbMessageOverview) main).addNewMessage( new FacebookMessage(bundle.getString("fb_name"), bundle.getString("fb_message"), bundle.getString("fb_img"), bundle.getLong("fb_id"), bundle.getString("fb_tid"))); } else if (main instanceof FbMessageOverview && bundle.getString("type").equals("readreceipt")) { ((FbMessageOverview) main).changeReadReceipt(bundle.getLong("fb_time"), bundle.getLong("fb_reader")); } else if (main instanceof FbMessageOverview && bundle.getString("type").equals("typ")) { ((FbMessageOverview) main).changeTypingStatus(bundle.getLong("my_id"), bundle.getLong("fb_id"), bundle.getBoolean("fb_from_mobile"), bundle.getInt("fb_status")); } else if (main instanceof FbMessageOverview && bundle.getString("type").equals("img_message")) { ((FbMessageOverview) main).addNewMessage(new FacebookImageMessage(bundle.getString("fb_name"), bundle.getString("fb_image"), bundle.getString("fb_preview"), bundle.getString("fb_img"), bundle.getLong("fb_id"), bundle.getString("fb_tid"))); } else if (bundle.getString("type").equals("read")) { killNotification(context, new MarkAsRead(bundle.getString("fb_tid"), bundle.getBoolean("fb_markas"))); } else if (bundle.getString("type").equals("message") || bundle.getString("type").equals("img_message")) { sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); if (!sharedPrefs.getBoolean("notification_fbs", true)) return; notify = sharedPrefs.getBoolean("notifications", true); vibrate = sharedPrefs.getBoolean("vibration", true); headsup = sharedPrefs.getBoolean("headsup", true); led_color = sharedPrefs.getInt("notification_light", -16776961); boolean all = sharedPrefs.getBoolean("all_fb", true); if (notify == false) return; if (bundle.getLong("fb_id") == bundle.getLong("my_id")) { return; } NotificationCompat.Builder mBuilder = null; boolean use_profile_picture = false; Bitmap profile_picture = null; String origin_name = bundle.getString("fb_name"); try { profile_picture = RoundedImageView.getCroppedBitmap(Bitmap.createScaledBitmap( ProfilePictureCache.getInstance(context).get(origin_name), 200, 200, false), 300); use_profile_picture = true; } catch (Exception e) { use_profile_picture = false; } Resources res = context.getResources(); if (bundle.getString("type").equals("img_message")) { bundle.putString("fb_message", res.getString(R.string.fb_notification_new_image)); } int lastIndex = bundle.getString("fb_message").lastIndexOf("="); if (lastIndex > 0 && Base64.isBase64(bundle.getString("fb_message").substring(0, lastIndex))) { mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.raven_notification_icon).setContentTitle(origin_name) .setColor(0xFF175ea2) .setContentText(res.getString(R.string.sms_receiver_new_encrypted_fb)) .setAutoCancel(true); if (use_profile_picture && profile_picture != null) { mBuilder = mBuilder.setLargeIcon(profile_picture); } else { mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name, context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200)); } } else { // normal or handshake if (bundle.getString("fb_message").charAt(0) == '%' && (bundle.getString("fb_message").length() == 10 || bundle.getString("fb_message").length() == 9)) { if (lastIndex > 0 && Base64.isBase64(bundle.getString("fb_message").substring(1, lastIndex))) { mBuilder = new NotificationCompat.Builder(context).setContentTitle(origin_name) .setColor(0xFF175ea2) .setContentText(res.getString(R.string.sms_receiver_handshake_received)) .setSmallIcon(R.drawable.notification_icon).setAutoCancel(true); if (use_profile_picture && profile_picture != null) { mBuilder = mBuilder.setLargeIcon(profile_picture); } else { mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name, context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200)); } } else { return; } } else if (bundle.getString("fb_message").charAt(0) == '%' && bundle.getString("fb_message").length() >= 120 && bundle.getString("fb_message").length() < 125) { if (lastIndex > 0 && Base64.isBase64(bundle.getString("fb_message").substring(1, lastIndex))) { mBuilder = new NotificationCompat.Builder(context).setContentTitle(origin_name) .setColor(0xFF175ea2) .setContentText(res.getString(R.string.sms_receiver_handshake_received)) .setSmallIcon(R.drawable.notification_icon).setAutoCancel(true); if (use_profile_picture && profile_picture != null) { mBuilder = mBuilder.setLargeIcon(profile_picture); } else { mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name, context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200)); } } else { return; } } else if (all) { // normal message mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.raven_notification_icon).setContentTitle(origin_name) .setColor(0xFF175ea2).setContentText(bundle.getString("fb_message")) .setAutoCancel(true).setStyle(new NotificationCompat.BigTextStyle() .bigText(bundle.getString("fb_message"))); if (use_profile_picture && profile_picture != null) { mBuilder = mBuilder.setLargeIcon(profile_picture); } else { mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name, context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200)); } } else { return; } } // } Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); mBuilder.setSound(alarmSound); mBuilder.setLights(led_color, 750, 4000); if (vibrate) { mBuilder.setVibrate(new long[] { 0, 100, 200, 300 }); } Intent resultIntent = new Intent(context, MainActivity.class); resultIntent.putExtra("FACEBOOK_NAME", origin_name); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(1, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); if (Build.VERSION.SDK_INT >= 16 && headsup) mBuilder.setPriority(Notification.PRIORITY_HIGH); if (Build.VERSION.SDK_INT >= 21) mBuilder.setCategory(Notification.CATEGORY_MESSAGE); final NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); if (!MainActivity.isOnTop) mNotificationManager.notify(8, mBuilder.build()); } } catch (Exception e) { e.printStackTrace(); } }