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:co.mindquake.nester.pushNoti.GcmIntentService.java
private void sendNotification(String msg, Bundle extras) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class).putExtra("notification", "true") .putExtra("uuid", extras.getString("uuid")).putExtra("title", extras.getString("title")), PendingIntent.FLAG_UPDATE_CURRENT); long[] vibrate = { 0, 100, 200, 300 }; NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.push_icon).setContentTitle(extras.getString("title")) .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg) .setVibrate(vibrate).setLights(Color.YELLOW, 500, 500).setAutoCancel(true); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
From source file:com.ashish.msngr.GCMNotificationIntentService.java
private void sendNotification(String msg) { Log.d(TAG, "Preparing to send notification...: " + msg); mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); Intent i = new Intent(this, RegisterActivity.class); i.putExtra("msg", msg); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.gcm_cloud).setContentTitle("Ashish's Messenger") .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg) .setSound(Settings.System.DEFAULT_NOTIFICATION_URI); mBuilder.setContentIntent(contentIntent); mNotificationManager.cancel(NOTIFICATION_ID); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); Log.d(TAG, "Notification sent successfully."); }
From source file:com.codeskraps.lolo.misc.Utils.java
public static PendingIntent getOnTouchIntent(Context context) { PendingIntent pendingIntent = null;// w ww . java2 s . c om Intent intent = null; SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); int onClick = Integer.parseInt(prefs.getString(Constants.ONCLICK, "0")); switch (onClick) { case 0: intent = new Intent("com.codeskraps.lol.DO_NOTHING"); pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); break; case 1: intent = new Intent(context, TweetsFeedActivity.class); pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); break; case 2: intent = new Intent(); intent.setAction(Constants.BROADCAST_RECEIVER); pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); break; case 3: intent = new Intent(context, PrefsActivity.class); pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); break; case 4: intent = new Intent(Intent.ACTION_VIEW); String url = prefs.getString(Constants.EURL, context.getString(R.string.prefsURL_default)); if (!url.startsWith("http://")) url = "http://" + url; intent.setData(Uri.parse(url)); pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); break; } return pendingIntent; }
From source file:com.belatrix.events.utils.fcm.EventsFirebaseMessagingService.java
private void sendNotification(String messageTitle, String messageBody) { Intent intent = MainActivity.makeIntent(this); intent.putExtra(MainActivity.PARAM_FROM_NOTIFICATION, true); intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT); NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle(); bigTextStyle.setBigContentTitle(messageTitle); bigTextStyle.bigText(messageBody);/*from w w w.java 2 s .c om*/ Bitmap icon = BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.ic_launcher); Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.bx_connect_white).setLargeIcon(icon).setStyle(bigTextStyle) .setContentText(messageBody).setContentTitle(messageTitle).setAutoCancel(true) .setContentIntent(pendingIntent).setSound(alarmSound).setLights(0xFF8F0300, 1000, 200) .setPriority(Notification.PRIORITY_MAX); //for vibration Vibrator v = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE); v.vibrate(1000); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); long time = new Date().getTime(); String tmpStr = String.valueOf(time); String last4Str = tmpStr.substring(tmpStr.length() - 5); int notificationId = Integer.valueOf(last4Str); notificationManager.notify(notificationId, notificationBuilder.build()); }
From source file:com.android.transmart.services.PlaceCheckinService.java
@Override public void onCreate() { super.onCreate(); contentResolver = getContentResolver(); cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); sharedPreferences = getSharedPreferences(LocationConstants.SHARED_PREFERENCE_FILE, Context.MODE_PRIVATE); sharedPreferencesEditor = sharedPreferences.edit(); sharedPref = PlatformSpecific.getSharedPreferenceSaver(this); Intent retryIntent = new Intent(LocationConstants.RETRY_QUEUED_CHECKINS_ACTION); retryQueuedCheckinsPendingIntent = PendingIntent.getBroadcast(this, 0, retryIntent, PendingIntent.FLAG_UPDATE_CURRENT); }
From source file:com.android.talkbacktests.testsession.NotificationTest.java
private void showSimpleNotification() { NotificationCompat.Builder builder = new NotificationCompat.Builder(getContext()) .setSmallIcon(android.R.drawable.ic_notification_overlay).setAutoCancel(true) .setContentTitle(getString(R.string.normal_notification_title)) .setContentText(getString(R.string.normal_notification_text)) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); TaskStackBuilder stackBuilder = TaskStackBuilder.create(getContext()); stackBuilder.addParentStack(MainActivity.class); Intent resultIntent = new Intent(getContext(), MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(resultPendingIntent); NotificationManager notificationManager = (NotificationManager) getContext() .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(NOTIFICATION_ID_MAIN_MENU, builder.build()); }
From source file:com.example.AllSOSservice.GcmBroadcastReceiver.java
@Override public void onReceive(Context context, Intent intent) { // Explicitly specify that GcmIntentService will handle the intent. ComponentName comp = new ComponentName(context.getPackageName(), Activity.class.getName()); // Start the service, keeping the device awake while it is launching. startWakefulService(context, (intent.setComponent(comp))); setResultCode(Activity.RESULT_OK);//from w w w. ja va2 s. co m String message = intent.getStringExtra("message"); String email = intent.getStringExtra("email"); String latitude = intent.getStringExtra("latitude"); String longitude = intent.getStringExtra("longitude"); Toast toast = Toast.makeText(context, message, Toast.LENGTH_LONG); toast.show(); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_launcher).setContentTitle("Novo Pedido de Ajuda!") .setContentText("Alguem precisa de um " + message); Intent resultIntent = null; try { if (isLoggedIn()) { resultIntent = new Intent(context, LoggedInActivity.class); } else { resultIntent = new Intent(context, LoginActivity.class); } } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } catch (TimeoutException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } // Because clicking the notification opens a new ("special") activity, there's // no need to create an artificial back stack. PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); int mNotificationId = 001; // Gets an instance of the NotificationManager service NotificationManager mNotifyMgr = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); // Builds the notification and issues it. mNotifyMgr.notify(mNotificationId, mBuilder.build()); }
From source file:com.kasoft.pushnot.GcmIntentService.java
private void sendNotification(String msg, String title, String form) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); Intent appMainIntent = new Intent(getApplicationContext(), MainActivity.class); appMainIntent.putExtra("title", title); appMainIntent.putExtra("form", form); //appMainIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); appMainIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, appMainIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_gcm).setContentTitle(title) .setStyle(new NotificationCompat.BigTextStyle().bigText(form)).setContentText(form); mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
From source file:com.android.tripgenie.auto.MessagingService.java
private void sendNotificationForConversation(int conversationId, String sender, String message, long timestamp) { String contentTitle;//from www . j a va 2 s .c o m if (message.indexOf(" is ") > 0) { contentTitle = message.substring(0, message.indexOf(" is ")); } else { contentTitle = message; } // A pending Intent for reads PendingIntent readPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), conversationId, getMessageReadIntent(conversationId), PendingIntent.FLAG_UPDATE_CURRENT); /// Add the code to create the UnreadConversation // Build a RemoteInput for receiving voice input in a Car Notification RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY).build(); // Building a Pending Intent for the reply action to trigger PendingIntent replyIntent = PendingIntent.getBroadcast(getApplicationContext(), conversationId, getMessageReplyIntent(conversationId), PendingIntent.FLAG_UPDATE_CURRENT); // Create the UnreadConversation and populate it with the participant name, // read and reply intents. UnreadConversation.Builder unreadConversationBuilder = new UnreadConversation.Builder(contentTitle) .setLatestTimestamp(timestamp).setReadPendingIntent(readPendingIntent) .setReplyAction(replyIntent, remoteInput); // Note: Add messages from oldest to newest to the UnreadConversation.Builder // Since we are sending a single message here we simply add the message. // In a real world application there could be multiple messages which should be ordered // and added from oldest to newest. unreadConversationBuilder.addMessage(message); /// End create UnreadConversation NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext()) .setSmallIcon(R.drawable.notification_icon) .setLargeIcon(BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.android_contact)) .setContentText(message) //.setWhen(timestamp) .setOngoing(true).setContentTitle(contentTitle).setContentIntent(readPendingIntent) /// Extend the notification with CarExtender. .extend(new CarExtender().setUnreadConversation(unreadConversationBuilder.build())) /// End ; Log.d(TAG, "Sending notification " + conversationId + " conversation: " + message); NotificationManagerCompat.from(this).notify(conversationId, builder.build()); }
From source file:at.andreasrohner.spartantimelapserec.BackgroundService.java
private void createNotification(int id) { NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(settings.getNotificationIcon()).setContentTitle(getString(R.string.app_name)) .setContentText(getString(R.string.notification_content_text)); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(this, MainActivity.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(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); builder.setContentIntent(resultPendingIntent); Notification notification = builder.build(); // Start foreground service to avoid unexpected kill startForeground(id, notification);//www.j a v a2 s.c o m }