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:net.frygo.findmybuddy.GCMIntentService.java
private static void generateAcceptfriendNotification(Context context, String message, String status) { Random rand = new Random(); int x = rand.nextInt(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, customlistview.class); if (status.equalsIgnoreCase("accept")) message = message + " added you as buddy"; else//w w w . j a v a2 s . co m message = message + " rejected you as buddy"; PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_CANCEL_CURRENT); Notification notification = new Notification(R.drawable.logo, message, System.currentTimeMillis()); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(x, notification); PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock mWakelock = pm .newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, title); mWakelock.acquire(); // Timer before putting Android Device to sleep mode. Timer timer = new Timer(); TimerTask task = new TimerTask() { public void run() { mWakelock.release(); } }; timer.schedule(task, 5000); }
From source file:com.carpool.dj.carpool.model.GcmIntentService.java
/** * Issues a notification to inform the user that server has sent a message. */// w ww. j a va2 s .c om @SuppressWarnings("deprecation") private static void generateNotification(Context context, String message, Bundle data, String type) { int icon = R.drawable.ic_launcher; long when = System.currentTimeMillis(); Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); // Notification notification = new Notification(icon, message, when); Notification notification = new Notification.Builder(context) .setContentTitle(Utils.nowActivity.getString(R.string.app_name)).setContentText(message) .setSmallIcon(icon).setWhen(when).setSound(alarmSound).build(); // String title = context.getString(R.string.app_name); Intent notificationIntent = null; if ("CarEvent".equals(type)) { notificationIntent = new Intent(context, ContentActivity.class); } else { return; } notificationIntent.putExtras(data); // set intent so it does not start a new activity notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(context, Utils.nowActivity.getString(R.string.app_name), message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); }
From source file:ca.rmen.android.networkmonitor.app.service.NetMonNotification.java
/** * Shows a notification with the given ticker text and content text. The icon is a warning icon, and the notification title is the app name. Tapping on the * notification opens the given activity. *//*from w ww . j a v a 2 s . co m*/ private static void showNotification(Context context, int notificationId, int tickerTextId, int contentTextId, Class<?> activityClass) { NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setSmallIcon(R.drawable.ic_stat_warning); builder.setAutoCancel(true); builder.setTicker(context.getString(tickerTextId)); builder.setContentTitle(context.getString(R.string.app_name)); builder.setContentText(context.getString(contentTextId)); builder.setAutoCancel(false); Uri uri = NetMonPreferences.getInstance(context).getNotificationSoundUri(); builder.setSound(uri); builder.setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, activityClass), PendingIntent.FLAG_UPDATE_CURRENT)); Notification notification = builder.build(); notification.flags |= Notification.FLAG_SHOW_LIGHTS | Notification.FLAG_ONLY_ALERT_ONCE; notification.ledARGB = 0xFFffff00; notification.ledOnMS = 300; notification.ledOffMS = 2000; NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(notificationId, notification); }
From source file:google.geofence.GooglegeofenceModule.java
/** * Gets a PendingIntent to send with the request to add or remove Geofences. * Location Services issues the Intent inside this PendingIntent whenever a * geofence transition occurs for the current list of geofences. * // w w w .j ava2 s . c o m * @return A PendingIntent for the IntentService that handles geofence * transitions. */ @Kroll.method private PendingIntent getGeofencePendingIntent() { // Reuse the PendingIntent if we already have it. if (mGeofencePendingIntent != null) { return mGeofencePendingIntent; } System.out.println("ATTEMPTING TO start service"); Intent intent = null; try { intent = new Intent(appContext, GeofenceTransitionsIntentService.class); TiApplication.getInstance().startService(intent); System.out.println("geoFenceTransitionsIntentService Created"); } catch (Exception ex) { System.out.println("Exception caught " + ex); } // We use FLAG_UPDATE_CURRENT so that we get the same pending intent // back when calling // addGeofences() and removeGeofences(). return PendingIntent.getService(appContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); }
From source file:com.automated.taxinow.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *//* w w w . j a v a 2 s .c o m*/ private void generateNotification(Context context, String message) { // System.out.println("this is message " + message); // System.out.println("NOTIFICATION RECEIVED!!!!!!!!!!!!!!" + message); int icon = R.drawable.ic_launcher; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, message, when); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, MainDrawerActivity.class); notificationIntent.putExtra("fromNotification", "notification"); // set intent so it does not start a new activity notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; System.out.println("notification====>" + message); notification.defaults |= Notification.DEFAULT_SOUND; notification.defaults |= Notification.DEFAULT_VIBRATE; // notification.defaults |= Notification.DEFAULT_LIGHTS; notification.flags |= Notification.FLAG_SHOW_LIGHTS; notification.ledARGB = 0x00000000; notification.ledOnMS = 0; notification.ledOffMS = 0; notificationManager.notify(0, notification); PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wakeLock = pm.newWakeLock( PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "WakeLock"); wakeLock.acquire(); wakeLock.release(); }
From source file:com.arcusapp.soundbox.player.MediaPlayerNotification.java
private void setUpMediaPlayerActions() { //open the PlayActivity when the user clicks the notification Intent notificationIntent = new Intent(SoundBoxApplication.getContext(), MainActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent clickPendingIntent = PendingIntent.getActivity(SoundBoxApplication.getContext(), 1, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); mNotificationBuilder.setContentIntent(clickPendingIntent); Intent togglePlayPauseIntent = new Intent(MediaPlayerService.TOGGLEPLAYPAUSE_ACTION, null, SoundBoxApplication.getContext(), MediaPlayerService.class); PendingIntent togglePlayPausePendingIntent = PendingIntent.getService(SoundBoxApplication.getContext(), 2, togglePlayPauseIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBaseView.setOnClickPendingIntent(R.id.notificationBasePlay, togglePlayPausePendingIntent); mExpandedView.setOnClickPendingIntent(R.id.notificationExpandedPlay, togglePlayPausePendingIntent); Intent nextIntent = new Intent(MediaPlayerService.NEXT_ACTION, null, SoundBoxApplication.getContext(), MediaPlayerService.class); PendingIntent nextPendingIntent = PendingIntent.getService(SoundBoxApplication.getContext(), 3, nextIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBaseView.setOnClickPendingIntent(R.id.notificationBaseNext, nextPendingIntent); mExpandedView.setOnClickPendingIntent(R.id.notificationExpandedNext, nextPendingIntent); Intent collapseIntent = new Intent(MediaPlayerService.STOP_ACTION, null, SoundBoxApplication.getContext(), MediaPlayerService.class); PendingIntent collapsePendingIntent = PendingIntent.getService(SoundBoxApplication.getContext(), 4, collapseIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBaseView.setOnClickPendingIntent(R.id.notificationBaseCollapse, collapsePendingIntent); mExpandedView.setOnClickPendingIntent(R.id.notificationExpandedCollapse, collapsePendingIntent); Intent previousIntent = new Intent(MediaPlayerService.PREVIOUS_ACTION, null, SoundBoxApplication.getContext(), MediaPlayerService.class); PendingIntent previousPendingIntent = PendingIntent.getService(SoundBoxApplication.getContext(), 5, previousIntent, PendingIntent.FLAG_UPDATE_CURRENT); mExpandedView.setOnClickPendingIntent(R.id.notificationExpandedPrevious, previousPendingIntent); }
From source file:com.chilliworks.chillisource.core.LocalNotificationReceiver.java
/** * Called when a local notification broad cast is received. Funnels the notification * into the app if open or into the notification bar if not * //from ww w .j a va 2s .c o m * @author Steven Hendrie * * @param The context. * @param The intent. */ @SuppressWarnings("deprecation") @Override public void onReceive(Context in_context, Intent in_intent) { //evaluate whether or not the main engine activity is in the foreground boolean isAppInForeground = false; if (CSApplication.get() != null && CSApplication.get().isActive() == true) { isAppInForeground = true; } //if the main engine activity is in the foreground, simply pass the //notification into it. Otherwise display a notification. if (isAppInForeground == true) { final Intent intent = new Intent(in_intent.getAction()); Bundle mapParams = in_intent.getExtras(); Iterator<String> iter = mapParams.keySet().iterator(); while (iter.hasNext()) { String strKey = iter.next(); intent.putExtra(strKey, mapParams.get(strKey).toString()); } LocalNotificationNativeInterface localNotificationNI = (LocalNotificationNativeInterface) CSApplication .get().getSystem(LocalNotificationNativeInterface.InterfaceID); if (localNotificationNI != null) { localNotificationNI.onNotificationReceived(intent); } } else { //aquire a wake lock if (s_wakeLock != null) { s_wakeLock.release(); } PowerManager pm = (PowerManager) in_context.getSystemService(Context.POWER_SERVICE); s_wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "NotificationWakeLock"); s_wakeLock.acquire(); //pull out the information from the intent Bundle params = in_intent.getExtras(); CharSequence title = params.getString(k_paramNameTitle); CharSequence text = params.getString(k_paramNameBody); int intentId = params.getInt(LocalNotification.k_paramNameNotificationId); int paramSize = params.size(); String[] keys = new String[paramSize]; String[] values = new String[paramSize]; Iterator<String> iter = params.keySet().iterator(); int paramNumber = 0; while (iter.hasNext()) { keys[paramNumber] = iter.next(); values[paramNumber] = params.get(keys[paramNumber]).toString(); ++paramNumber; } Intent openAppIntent = new Intent(in_context, CSActivity.class); openAppIntent.setAction("android.intent.action.MAIN"); openAppIntent.addCategory("android.intent.category.LAUNCHER"); openAppIntent.putExtra(k_appOpenedFromNotification, true); openAppIntent.putExtra(k_arrayOfKeysName, keys); openAppIntent.putExtra(k_arrayOfValuesName, values); openAppIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent sContentIntent = PendingIntent.getActivity(in_context, intentId, openAppIntent, PendingIntent.FLAG_UPDATE_CURRENT); Bitmap largeIconBitmap = null; int LargeIconID = ResourceHelper.GetDynamicResourceIDForField(in_context, ResourceHelper.RESOURCE_SUBCLASS.RESOURCE_DRAWABLE, "ic_stat_notify_large"); //Use small icon if no large icon if (LargeIconID == 0) { LargeIconID = ResourceHelper.GetDynamicResourceIDForField(in_context, ResourceHelper.RESOURCE_SUBCLASS.RESOURCE_DRAWABLE, "ic_stat_notify"); } if (LargeIconID > 0) { largeIconBitmap = BitmapFactory.decodeResource(in_context.getResources(), LargeIconID); } Notification notification = new NotificationCompat.Builder(in_context).setContentTitle(title) .setContentText(text) .setSmallIcon(ResourceHelper.GetDynamicResourceIDForField(in_context, ResourceHelper.RESOURCE_SUBCLASS.RESOURCE_DRAWABLE, "ic_stat_notify")) .setLargeIcon(largeIconBitmap).setContentIntent(sContentIntent).build(); NotificationManager notificationManager = (NotificationManager) in_context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(intentId, notification); Toast.makeText(in_context, text, Toast.LENGTH_LONG).show(); } }
From source file:ar.fiuba.jobify.JobifyChat.java
/** * Called when message is received.//w w w . ja v a 2s . c o m * * @param remoteMessage Object representing the message received from Firebase Cloud Messaging. */ // [START receive_message] @Override public void onMessageReceived(RemoteMessage remoteMessage) { // [START_EXCLUDE] // There are two types of messages data messages and notification messages. Data messages are handled // here in onMessageReceived whether the app is in the foreground or background. Data messages are the type // traditionally used with GCM. Notification messages are only received here in onMessageReceived when the app // is in the foreground. When the app is in the background an automatically generated notification is displayed. // When the user taps on the notification they are returned to the app. Messages containing both notification // and data payloads are treated as notification messages. The Firebase console always sends notification // messages. For more see: https://firebase.google.com/docs/cloud-messaging/concept-options // [END_EXCLUDE] // Not getting messages here? See why this may be: https://goo.gl/39bRNJ Log.d(TAG, "From: " + remoteMessage.getFrom()); // Check if message contains a data payload. if (remoteMessage.getData().size() > 0) { String body = remoteMessage.getData() + ""; Log.d(TAG, "Message data payload: " + body); JsonParser parser = new JsonParser(); //JsonObject message = parser.parse(body).getAsJsonObject(); JSONObject message = null; try { message = new JSONObject(body); } catch (JSONException e) { e.printStackTrace(); } if (message.has("mensaje")) { long sender = 0, receiver = 0; try { receiver = message.getJSONObject("mensaje").getLong("to"); sender = message.getJSONObject("mensaje").getLong("from"); } catch (JSONException e) { e.printStackTrace(); } long currentId = getSharedPreferences(getString(R.string.shared_pref_connected_user), 0) .getLong(getString(R.string.stored_connected_user_id), -1); //Log.d("MYTAG", editor.g getLong( getString(R.string.stored_connected_user_id))); if (receiver != currentId) { // la app no esta abierta return; } if (!(ConversacionActivity.activityVisible && ConversacionActivity.corresponsalID == sender)) { NotificationCompat.Builder mBuilder = null; try { mBuilder = new NotificationCompat.Builder(this).setContentTitle("Nuevo mensaje") .setSmallIcon(R.drawable.common_google_signin_btn_icon_dark).setAutoCancel(true) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.mensaje)) .setSmallIcon(R.drawable.logo_v2_j_square) .setContentText(message.getJSONObject("mensaje").getString("message")); } catch (JSONException e) { e.printStackTrace(); } //ConversacionActivity. Intent resultIntent = new Intent(this, ConversacionActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(ConversacionActivity.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(resultIntent); resultIntent.putExtra(ConversacionActivity.CORRESPONSAL_ID_MESSAGE, (long) sender); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); Random r = new Random(); mNotificationManager.notify(r.nextInt(1000000000), mBuilder.build()); } // notify chat try { EventBus.getDefault().post(new MessageEvent(message.getJSONObject("mensaje"))); } catch (JSONException e) { e.printStackTrace(); } } else if (message.has("solicitud")) { long receiver = 0; try { receiver = message.getJSONObject("solicitud").getLong("toId"); } catch (JSONException e) { e.printStackTrace(); } long currentId = getSharedPreferences(getString(R.string.shared_pref_connected_user), 0) .getLong(getString(R.string.stored_connected_user_id), -1); //Log.d("MYTAG", editor.g getLong( getString(R.string.stored_connected_user_id))); if (receiver != currentId) { // la app no esta abierta return; } NotificationCompat.Builder mBuilder = null; try { mBuilder = new NotificationCompat.Builder(this).setContentTitle("Nueva solicitud") .setSmallIcon(R.drawable.common_google_signin_btn_icon_dark).setAutoCancel(true) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.solicitud)) .setSmallIcon(R.drawable.logo_v2_j_square) .setContentText(message.getJSONObject("solicitud").getString("fromNombre")); } catch (JSONException e) { e.printStackTrace(); } Intent resultIntent = new Intent(this, UserListActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(UserListActivity.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(resultIntent); resultIntent.putExtra(UserListActivity.LIST_MODE_MESSAGE, UserListActivity.MODE_SOLICITUDES); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); Random r = new Random(); mNotificationManager.notify(r.nextInt(1000000000), mBuilder.build()); } // if this is a notification: // TODO // here we call the callback to the activity // if this is a message: } // Check if message contains a notification payload. if (remoteMessage.getNotification() != null) { Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody()); } // Also if you intend on generating your own notifications as a result of a received FCM // message, here is where that should be initiated. See sendNotification method below. }
From source file:com.matze5800.paupdater.Functions.java
public static void Notify(Context context, String text) { Log.i("notify", text); Notification.Builder nBuilder; nBuilder = new Notification.Builder(context); Intent resultIntent = new Intent(context, Cancel.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(Cancel.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); nBuilder.setContentIntent(resultPendingIntent); nBuilder.setSmallIcon(R.drawable.ic_launcher); nBuilder.setContentTitle("PA Updater"); nBuilder.setContentText(text);//from ww w. j a va2s .c o m nBuilder.setAutoCancel(false); nBuilder.setOngoing(true); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(1, nBuilder.build()); }
From source file:com.cloverstudio.spika.GCMIntentService.java
@SuppressWarnings("deprecation") public void triggerNotification(Context context, String message, String fromName, Bundle pushExtras) { if (fromName != null) { final NotificationManager notificationManager = (NotificationManager) getSystemService( NOTIFICATION_SERVICE);//from w ww . j av a 2 s . c o m Notification notification = new Notification(R.drawable.icon_notification, message, System.currentTimeMillis()); notification.number = mNotificationCounter + 1; mNotificationCounter = mNotificationCounter + 1; Intent intent = new Intent(this, SplashScreenActivity.class); intent.replaceExtras(pushExtras); intent.putExtra(Const.PUSH_INTENT, true); intent.setAction(Long.toString(System.currentTimeMillis())); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_FROM_BACKGROUND | Intent.FLAG_ACTIVITY_TASK_ON_HOME); PendingIntent pendingIntent = PendingIntent.getActivity(this, notification.number, intent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(this, context.getString(R.string.app_name), message, pendingIntent); notification.defaults |= Notification.DEFAULT_VIBRATE; notification.defaults |= Notification.DEFAULT_SOUND; notification.flags |= Notification.FLAG_AUTO_CANCEL; String notificationId = Double.toString(Math.random()); notificationManager.notify(notificationId, 0, notification); } }