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.raceyourself.android.samsung.ProviderService.java
private void enableIcon() { if (iconEnabled) return;/*from www . j a v a 2s.c om*/ iconEnabled = true; NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.rylogo) .setContentTitle(getString(R.string.notification_title)) .setContentText(getString(R.string.notification_message)); Intent intent = new Intent(this, PopupActivity.class); PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); // Gets an instance of the NotificationManager service NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // Builds the notification and issues it. mNotifyMgr.notify(TETHER_NOTIFICATION_ID, mBuilder.build()); }
From source file:com.android.mail.utils.NotificationUtils.java
private static PendingIntent createClickPendingIntent(Context context, Intent notificationIntent) { // Amend the click intent with a hint that its source was a notification, // but remove the hint before it's used to generate notification action // intents. This prevents the following sequence: // 1. generate single notification // 2. user clicks reply, then completes Compose activity // 3. main activity launches, gets FROM_NOTIFICATION hint in intent notificationIntent.putExtra(Utils.EXTRA_FROM_NOTIFICATION, true); PendingIntent clickIntent = PendingIntent.getActivity(context, -1, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); notificationIntent.removeExtra(Utils.EXTRA_FROM_NOTIFICATION); return clickIntent; }
From source file:com.skywomantechnology.app.guildviewer.sync.GuildViewerSyncAdapter.java
/** * Handles setting up the notification./*from ww w . j a v a 2 s . co m*/ * There are two situation in which we send a notification * First if there is more recent news than the last sync * Second if the news is concerned with the favorite character * @param context to use for getting preference information * @param newsItem contains the newsItem information used to build the notification * @param notification_id identifier for the notification */ private void notifyNews(Context context, GuildViewerNewsItem newsItem, int notification_id) { // determine if we should send a notification SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); boolean notificationsEnabled = prefs.getBoolean(context.getString(R.string.pref_enable_notifications_key), Boolean.parseBoolean(context.getString(R.string.pref_enable_notifications_default))); long lastNotification = prefs.getLong(context.getString(R.string.pref_last_notification), 0L); boolean timeToNotify = newsItem.getTimestamp() > lastNotification; // we can notify for both new news and for favorite character news if (notificationsEnabled && (timeToNotify || notification_id == GUILD_VIEWER_FAVORITE_CHARACTER_NOTIFICATION)) { // build the information to put into the notification int iconId = R.drawable.ic_launcher; String title = context.getString(R.string.app_name); String news = String.format("%s %s %s", newsItem.getCharacter(), Utility.getNewsTypeVerb(context, newsItem.getType()), Utility.containsItem(newsItem.getType()) ? ((newsItem.getItem() != null) ? newsItem.getItem().getName() : "") : ((newsItem.getAchievement() != null) ? newsItem.getAchievement().getTitle() : "")); String contentText = String.format(context.getString(R.string.format_notification), news); // set the notification to clear after a click NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context).setSmallIcon(iconId) .setContentTitle(title).setContentText(contentText).setOnlyAlertOnce(true).setAutoCancel(true); // Open the app when the user clicks on the notification. Intent resultIntent = new Intent(context, NewsListActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context).addParentStack(NewsListActivity.class) .addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); // we can notify for two reasons but lets just always have one notification at a time NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(GUILD_VIEWER_NOTIFICATION_ID, mBuilder.build()); } }
From source file:eu.faircode.adblocker.ServiceSinkhole.java
private Builder getBuilder(List<Rule> listAllowed, List<Rule> listRule) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); boolean tethering = prefs.getBoolean("tethering", false); boolean filter = prefs.getBoolean("filter", false); boolean system = prefs.getBoolean("manage_system", false); // Build VPN service Builder builder = new Builder(); builder.setSession(getString(R.string.app_name)); // VPN address String vpn4 = prefs.getString("vpn4", "10.1.10.1"); String vpn6 = prefs.getString("vpn6", "fd00:1:fd00:1:fd00:1:fd00:1"); Log.i(TAG, "vpn4=" + vpn4 + " vpn6=" + vpn6); builder.addAddress(vpn4, 32);//from w ww .jav a2s . com builder.addAddress(vpn6, 128); // DNS address if (filter) for (InetAddress dns : getDns(ServiceSinkhole.this)) { Log.i(TAG, "dns=" + dns); builder.addDnsServer(dns); } if (tethering) { // USB Tethering 192.168.42.x // Wi-Fi Tethering 192.168.43.x // https://en.wikipedia.org/wiki/IPv4#Special-use_addresses builder.addRoute("0.0.0.0", 2); // 0-63 builder.addRoute("64.0.0.0", 3); // 64-95 builder.addRoute("96.0.0.0", 4); // 96-111 builder.addRoute("112.0.0.0", 5); // 112-119 builder.addRoute("120.0.0.0", 6); // 120-123 builder.addRoute("124.0.0.0", 7); // 124-125 builder.addRoute("126.0.0.0", 8); // 126 // skip 127.0.0.0/8 - localhost builder.addRoute("128.0.0.0", 2); // 128-191 builder.addRoute("192.0.0.0", 9); // 192.0-192.127 builder.addRoute("192.128.0.0", 11); // 192.128-192.159 builder.addRoute("192.160.0.0", 13); // 192.160-192.167 builder.addRoute("192.168.0.0", 19); // 192.168.0-192.168.31 builder.addRoute("192.168.32.0", 21); // 192.168.32-192.168.39 builder.addRoute("192.168.40.0", 23); // 192.168.40-192.168.41 // skip 192.168.42 - 192.168.43 - tethering builder.addRoute("192.168.44.0", 22); // 192.168.44-192.168.47 builder.addRoute("192.168.48.0", 20); // 192.168.48-192.168.63 builder.addRoute("192.168.64.0", 18); // 192.168.64-192.168.127 builder.addRoute("192.168.128.0", 17); // 192.168.128-192.168.255 builder.addRoute("192.169.0.0", 16); // 192.169 builder.addRoute("192.170.0.0", 15); // 192.170-192.171 builder.addRoute("192.172.0.0", 14); // 192.172-192.175 builder.addRoute("192.176.0.0", 12); // 192.176-191.191 builder.addRoute("192.192.0.0", 10); // 192.192-192.255 builder.addRoute("193.0.0.0", 8); // 193 builder.addRoute("194.0.0.0", 7); // 194-195 builder.addRoute("196.0.0.0", 6); // 196-199 builder.addRoute("200.0.0.0", 5); // 200-207 builder.addRoute("208.0.0.0", 4); // 208-223 try { builder.addRoute("224.0.0.0", 4); // 224-239 builder.addRoute("240.0.0.0", 4); // 240-255 } catch (Throwable ex) { // Some Android versions do not accept broadcast addresses Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } } else builder.addRoute("0.0.0.0", 0); builder.addRoute("0:0:0:0:0:0:0:0", 0); // MTU int mtu = jni_get_mtu(); Log.i(TAG, "MTU=" + mtu); builder.setMtu(mtu); // Add list of allowed applications if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) if (last_connected && !filter) for (Rule rule : listAllowed) try { builder.addDisallowedApplication(rule.info.packageName); } catch (PackageManager.NameNotFoundException ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } else if (filter) for (Rule rule : listRule) if (!rule.apply || (!system && rule.system)) try { Log.i(TAG, "Not routing " + rule.info.packageName); builder.addDisallowedApplication(rule.info.packageName); } catch (PackageManager.NameNotFoundException ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } // Build configure intent Intent configure = new Intent(this, ActivityMain.class); PendingIntent pi = PendingIntent.getActivity(this, 0, configure, PendingIntent.FLAG_UPDATE_CURRENT); builder.setConfigureIntent(pi); return builder; }
From source file:com.lewa.crazychapter11.MainActivity.java
public boolean isLewaRom(Context context, Intent alarmIntent) { PackageManager pm = context.getPackageManager(); boolean isLewaRom = true; String version = ""; int versionCode = 0; PackageInfo pi = null;/*from w ww. ja v a 2 s . c o m*/ String testsr = null; try { // com.lewa.permmanager // pm.getPackageInfo("com.lewa.deviceactivate",PackageManager.GET_ACTIVITIES); pm.getPackageInfo("com.lewa.permmanager", PackageManager.GET_ACTIVITIES); pi = pm.getPackageInfo(context.getPackageName(), 0); version = pi.versionName; versionCode = pi.versionCode; } catch (PackageManager.NameNotFoundException e) { isLewaRom = false; } Log.d("algerheMain00", "isLewaRom : " + isLewaRom); Log.i("algerheVersion", "versionname=" + version + " \n getPackageName()=" + getPackageName() + " \n versioncode=" + versionCode); Log.i("algerheStr", "TextUtils.isEmpty(testsr) = " + TextUtils.isEmpty(testsr)); // Log.i("algerheStr","testsr.length="+testsr.length()); ///alarm test Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.set(Calendar.HOUR_OF_DAY, 16); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); alarmIntent.setAction("com.lewa.alarm.test"); PendingIntent pipi = PendingIntent.getBroadcast(context, 3359, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Log.i("algerheAlarm", "send alarm message in time=" + System.currentTimeMillis()); // alarmManager.setExact(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+5000, pipi); alarmManager.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pipi); // final Timer timer = new Timer(); // timer.schedule(new TimerTask() { // @Override // public void run() { // Message msg = new Message(); // msg.what = 0x2789; // handler.sendMessage(msg); // timer.cancel(); // } // }, 0, 5000); return isLewaRom; }
From source file:com.irccloud.android.Notifications.java
public NotificationCompat.Builder alert(int bid, String title, String body) { NotificationCompat.Builder builder = new NotificationCompat.Builder( IRCCloudApplication.getInstance().getApplicationContext()).setContentTitle(title) .setContentText(body).setTicker(body).setAutoCancel(true).setColor(IRCCloudApplication .getInstance().getApplicationContext().getResources().getColor(R.color.dark_blue)) .setSmallIcon(R.drawable.ic_stat_notify); Intent i = new Intent(); i.setComponent(new ComponentName(IRCCloudApplication.getInstance().getApplicationContext().getPackageName(), "com.irccloud.android.MainActivity")); i.putExtra("bid", bid); i.setData(Uri.parse("bid://" + bid)); builder.setContentIntent(/*from w w w.j ava2s .c o m*/ PendingIntent.getActivity(IRCCloudApplication.getInstance().getApplicationContext(), 0, i, PendingIntent.FLAG_UPDATE_CURRENT)); NotificationManagerCompat.from(IRCCloudApplication.getInstance().getApplicationContext()).notify(bid, builder.build()); return builder; }
From source file:co.beem.project.beem.FacebookTextService.java
private PendingIntent makeChatIntent(User user) { Intent chatIntent = new Intent(FacebookTextService.this, FbTextMainActivity.class); chatIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); try {/*from w ww . j a v a 2 s.c o m*/ chatIntent.setData(user.toUri()); } catch (Exception e) { Log.e(TAG, e.getMessage()); } PendingIntent contentIntent = PendingIntent.getActivity(FacebookTextService.this, 0, chatIntent, PendingIntent.FLAG_UPDATE_CURRENT); return contentIntent; }
From source file:com.bluros.music.MusicService.java
private Notification buildNotification() { final String albumName = getAlbumName(); final String artistName = getArtistName(); final boolean isPlaying = isPlaying(); String text = TextUtils.isEmpty(albumName) ? artistName : artistName + " - " + albumName; int playButtonResId = isPlaying ? R.drawable.ic_pause_white_36dp : R.drawable.ic_play_white_36dp; Intent nowPlayingIntent = NavigationUtils.getNowPlayingIntent(this); PendingIntent clickIntent = PendingIntent.getActivity(this, 0, nowPlayingIntent, PendingIntent.FLAG_UPDATE_CURRENT); Bitmap artwork;// w ww . j av a 2 s . c o m artwork = ImageLoader.getInstance().loadImageSync(MusicUtils.getAlbumArtUri(getAlbumId()).toString()); if (artwork == null) { artwork = ImageLoader.getInstance().loadImageSync("drawable://" + R.drawable.ic_empty_music2); } if (mNotificationPostTime == 0) { mNotificationPostTime = System.currentTimeMillis(); } android.support.v4.app.NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_notification).setLargeIcon(artwork).setContentIntent(clickIntent) .setContentTitle(getTrackName()).setContentText(text).setWhen(mNotificationPostTime) .addAction(R.drawable.ic_skip_previous_white_36dp, "", retrievePlaybackAction(PREVIOUS_ACTION)) .addAction(playButtonResId, "", retrievePlaybackAction(TOGGLEPAUSE_ACTION)) .addAction(R.drawable.ic_skip_next_white_36dp, "", retrievePlaybackAction(NEXT_ACTION)); if (MusicUtils.isJellyBeanMR1()) { builder.setShowWhen(false); } if (MusicUtils.isLollipop()) { builder.setVisibility(Notification.VISIBILITY_PUBLIC); NotificationCompat.MediaStyle style = new NotificationCompat.MediaStyle() .setMediaSession(mSession.getSessionToken()).setShowActionsInCompactView(0, 1, 2, 3); builder.setStyle(style); } if (artwork != null && MusicUtils.isLollipop()) builder.setColor(Palette.from(artwork).generate().getVibrantColor(Color.parseColor("#403f4d"))); Notification n = builder.build(); if (PreferencesUtility.getInstance(this).getXPosedTrackselectorEnabled()) { addXTrackSelector(n); } return n; }
From source file:br.com.bioscada.apps.biotracks.services.TrackRecordingService.java
/** * Shows the notification./*from w w w. j a v a 2 s . c o m*/ * * @param isGpsStarted true if GPS is started */ private void showNotification(boolean isGpsStarted) { if (isRecording()) { if (isPaused()) { stopForegroundService(); } else { Intent intent = IntentUtils.newIntent(this, TrackDetailActivity.class) .putExtra(TrackDetailActivity.EXTRA_TRACK_ID, recordingTrackId); PendingIntent pendingIntent = TaskStackBuilder.create(this) .addParentStack(TrackDetailActivity.class).addNextIntent(intent) .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); startForegroundService(pendingIntent, R.string.track_record_notification); } return; } else { // Not recording if (isGpsStarted) { Intent intent = IntentUtils.newIntent(this, TrackListActivity.class); PendingIntent pendingIntent = TaskStackBuilder.create(this).addNextIntent(intent) .getPendingIntent(0, 0); startForegroundService(pendingIntent, R.string.gps_starting); } else { stopForegroundService(); } } }
From source file:com.android.mms.transaction.MessagingNotification.java
/** * updateNotification is *the* main function for building the actual notification handed to * the NotificationManager/*from www. jav a 2 s . c om*/ * @param context * @param newThreadId the new thread id * @param uniqueThreadCount * @param notificationSet the set of notifications to display */ private static void updateNotification(Context context, long newThreadId, int uniqueThreadCount, SortedSet<NotificationInfo> notificationSet) { boolean isNew = newThreadId != THREAD_NONE; CMConversationSettings conversationSettings = CMConversationSettings.getOrNew(context, newThreadId); // If the user has turned off notifications in settings, don't do any notifying. if ((isNew && !conversationSettings.getNotificationEnabled()) || !MessagingPreferenceActivity.getNotificationEnabled(context)) { if (DEBUG) { Log.d(TAG, "updateNotification: notifications turned off in prefs, bailing"); } return; } // Figure out what we've got -- whether all sms's, mms's, or a mixture of both. final int messageCount = notificationSet.size(); NotificationInfo mostRecentNotification = notificationSet.first(); final NotificationCompat.Builder noti = new NotificationCompat.Builder(context) .setWhen(mostRecentNotification.mTimeMillis); if (isNew) { noti.setTicker(mostRecentNotification.mTicker); } // If we have more than one unique thread, change the title (which would // normally be the contact who sent the message) to a generic one that // makes sense for multiple senders, and change the Intent to take the // user to the conversation list instead of the specific thread. // Cases: // 1) single message from single thread - intent goes to ComposeMessageActivity // 2) multiple messages from single thread - intent goes to ComposeMessageActivity // 3) messages from multiple threads - intent goes to ConversationList final Resources res = context.getResources(); String title = null; Bitmap avatar = null; PendingIntent pendingIntent = null; boolean isMultiNewMessages = MessageUtils.isMailboxMode() ? messageCount > 1 : uniqueThreadCount > 1; if (isMultiNewMessages) { // messages from multiple threads Intent mainActivityIntent = getMultiThreadsViewIntent(context); pendingIntent = PendingIntent.getActivity(context, 0, mainActivityIntent, PendingIntent.FLAG_UPDATE_CURRENT); title = context.getString(R.string.message_count_notification, messageCount); } else { // same thread, single or multiple messages title = mostRecentNotification.mTitle; avatar = mostRecentNotification.mSender.getAvatar(context); noti.setSubText(mostRecentNotification.mSimName); // no-op in single SIM case if (avatar != null) { // Show the sender's avatar as the big icon. Contact bitmaps are 96x96 so we // have to scale 'em up to 128x128 to fill the whole notification large icon. final int idealIconHeight = res .getDimensionPixelSize(android.R.dimen.notification_large_icon_height); final int idealIconWidth = res.getDimensionPixelSize(android.R.dimen.notification_large_icon_width); noti.setLargeIcon(BitmapUtil.getRoundedBitmap(avatar, idealIconWidth, idealIconHeight)); } pendingIntent = PendingIntent.getActivity(context, 0, mostRecentNotification.mClickIntent, PendingIntent.FLAG_UPDATE_CURRENT); } // Always have to set the small icon or the notification is ignored noti.setSmallIcon(R.drawable.stat_notify_sms); NotificationManagerCompat nm = NotificationManagerCompat.from(context); // Update the notification. noti.setContentTitle(title).setContentIntent(pendingIntent) .setColor(context.getResources().getColor(R.color.mms_theme_color)) .setCategory(Notification.CATEGORY_MESSAGE).setPriority(Notification.PRIORITY_DEFAULT); // TODO: set based on contact coming // from a favorite. // Tag notification with all senders. for (NotificationInfo info : notificationSet) { Uri peopleReferenceUri = info.mSender.getPeopleReferenceUri(); if (peopleReferenceUri != null) { noti.addPerson(peopleReferenceUri.toString()); } } int defaults = 0; if (isNew) { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); if (conversationSettings.getVibrateEnabled()) { String pattern = conversationSettings.getVibratePattern(); if (!TextUtils.isEmpty(pattern)) { noti.setVibrate(parseVibratePattern(pattern)); } else { defaults |= Notification.DEFAULT_VIBRATE; } } String ringtoneStr = conversationSettings.getNotificationTone(); noti.setSound(TextUtils.isEmpty(ringtoneStr) ? null : Uri.parse(ringtoneStr)); Log.d(TAG, "updateNotification: new message, adding sound to the notification"); } defaults |= Notification.DEFAULT_LIGHTS; noti.setDefaults(defaults); // set up delete intent noti.setDeleteIntent(PendingIntent.getBroadcast(context, 0, sNotificationOnDeleteIntent, 0)); // See if QuickMessage pop-up support is enabled in preferences boolean qmPopupEnabled = MessagingPreferenceActivity.getQuickMessageEnabled(context); // Set up the QuickMessage intent Intent qmIntent = null; if (mostRecentNotification.mIsSms) { // QuickMessage support is only for SMS qmIntent = new Intent(); qmIntent.setClass(context, QuickMessagePopup.class); qmIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); qmIntent.putExtra(QuickMessagePopup.SMS_FROM_NAME_EXTRA, mostRecentNotification.mSender.getName()); qmIntent.putExtra(QuickMessagePopup.SMS_FROM_NUMBER_EXTRA, mostRecentNotification.mSender.getNumber()); qmIntent.putExtra(QuickMessagePopup.SMS_NOTIFICATION_OBJECT_EXTRA, mostRecentNotification); } // Start getting the notification ready final Notification notification; //Create a WearableExtender to add actions too WearableExtender wearableExtender = new WearableExtender(); if (messageCount == 1 || uniqueThreadCount == 1) { // Add the Quick Reply action only if the pop-up won't be shown already if (!qmPopupEnabled && qmIntent != null) { // This is a QR, we should show the keyboard when the user taps to reply qmIntent.putExtra(QuickMessagePopup.QR_SHOW_KEYBOARD_EXTRA, true); // Create the pending intent and add it to the notification CharSequence qmText = context.getText(R.string.menu_reply); PendingIntent qmPendingIntent = PendingIntent.getActivity(context, 0, qmIntent, PendingIntent.FLAG_UPDATE_CURRENT); noti.addAction(R.drawable.ic_reply, qmText, qmPendingIntent); //Wearable noti.extend(wearableExtender.addAction( new NotificationCompat.Action.Builder(R.drawable.ic_reply, qmText, qmPendingIntent) .build())); } // Add the 'Mark as read' action CharSequence markReadText = context.getText(R.string.qm_mark_read); Intent mrIntent = new Intent(); mrIntent.setClass(context, QmMarkRead.class); mrIntent.putExtra(QmMarkRead.SMS_THREAD_ID, mostRecentNotification.mThreadId); PendingIntent mrPendingIntent = PendingIntent.getBroadcast(context, 0, mrIntent, PendingIntent.FLAG_UPDATE_CURRENT); noti.addAction(R.drawable.ic_mark_read, markReadText, mrPendingIntent); // Add the Call action CharSequence callText = context.getText(R.string.menu_call); Intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.setData(Uri.parse("tel:" + mostRecentNotification.mSender.getNumber())); PendingIntent callPendingIntent = PendingIntent.getActivity(context, 0, callIntent, PendingIntent.FLAG_UPDATE_CURRENT); noti.addAction(R.drawable.ic_menu_call, callText, callPendingIntent); //Wearable noti.extend(wearableExtender.addAction( new NotificationCompat.Action.Builder(R.drawable.ic_menu_call, callText, callPendingIntent) .build())); //Set up remote input String replyLabel = context.getString(R.string.qm_wear_voice_reply); RemoteInput remoteInput = new RemoteInput.Builder(QuickMessageWear.EXTRA_VOICE_REPLY) .setLabel(replyLabel).build(); //Set up pending intent for voice reply Intent voiceReplyIntent = new Intent(context, QuickMessageWear.class); voiceReplyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); voiceReplyIntent.putExtra(QuickMessageWear.SMS_CONATCT, mostRecentNotification.mSender.getName()); voiceReplyIntent.putExtra(QuickMessageWear.SMS_SENDER, mostRecentNotification.mSender.getNumber()); voiceReplyIntent.putExtra(QuickMessageWear.SMS_THEAD_ID, mostRecentNotification.mThreadId); PendingIntent voiceReplyPendingIntent = PendingIntent.getActivity(context, 0, voiceReplyIntent, PendingIntent.FLAG_UPDATE_CURRENT); //Wearable voice reply action NotificationCompat.Action action = new NotificationCompat.Action.Builder(R.drawable.ic_reply, context.getString(R.string.qm_wear_reply_by_voice), voiceReplyPendingIntent) .addRemoteInput(remoteInput).build(); noti.extend(wearableExtender.addAction(action)); } if (messageCount == 1) { // We've got a single message // This sets the text for the collapsed form: noti.setContentText(mostRecentNotification.formatBigMessage(context)); if (mostRecentNotification.mAttachmentBitmap != null) { // The message has a picture, show that NotificationCompat.BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle(noti) .bigPicture(mostRecentNotification.mAttachmentBitmap) .setSummaryText(mostRecentNotification.formatPictureMessage(context)); notification = noti.setStyle(bigPictureStyle).build(); } else { // Show a single notification -- big style with the text of the whole message NotificationCompat.BigTextStyle bigTextStyle1 = new NotificationCompat.BigTextStyle(noti) .bigText(mostRecentNotification.formatBigMessage(context)); notification = noti.setStyle(bigTextStyle1).build(); } if (DEBUG) { Log.d(TAG, "updateNotification: single message notification"); } } else { // We've got multiple messages if (!isMultiNewMessages) { // We've got multiple messages for the same thread. // Starting with the oldest new message, display the full text of each message. // Begin a line for each subsequent message. SpannableStringBuilder buf = new SpannableStringBuilder(); NotificationInfo infos[] = notificationSet.toArray(new NotificationInfo[messageCount]); int len = infos.length; for (int i = len - 1; i >= 0; i--) { NotificationInfo info = infos[i]; buf.append(info.formatBigMessage(context)); if (i != 0) { buf.append('\n'); } } noti.setContentText(context.getString(R.string.message_count_notification, messageCount)); // Show a single notification -- big style with the text of all the messages NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle(); bigTextStyle.bigText(buf) // Forcibly show the last line, with the app's smallIcon in it, if we // kicked the smallIcon out with an avatar bitmap .setSummaryText((avatar == null) ? null : " "); notification = noti.setStyle(bigTextStyle).build(); if (DEBUG) { Log.d(TAG, "updateNotification: multi messages for single thread"); } } else { // Build a set of the most recent notification per threadId. HashSet<Long> uniqueThreads = new HashSet<Long>(messageCount); ArrayList<NotificationInfo> mostRecentNotifPerThread = new ArrayList<NotificationInfo>(); Iterator<NotificationInfo> notifications = notificationSet.iterator(); while (notifications.hasNext()) { NotificationInfo notificationInfo = notifications.next(); if (!uniqueThreads.contains(notificationInfo.mThreadId)) { uniqueThreads.add(notificationInfo.mThreadId); mostRecentNotifPerThread.add(notificationInfo); } } // When collapsed, show all the senders like this: // Fred Flinstone, Barry Manilow, Pete... noti.setContentText(formatSenders(context, mostRecentNotifPerThread)); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(noti); // We have to set the summary text to non-empty so the content text doesn't show // up when expanded. inboxStyle.setSummaryText(" "); // At this point we've got multiple messages in multiple threads. We only // want to show the most recent message per thread, which are in // mostRecentNotifPerThread. int uniqueThreadMessageCount = mostRecentNotifPerThread.size(); int maxMessages = Math.min(MAX_MESSAGES_TO_SHOW, uniqueThreadMessageCount); for (int i = 0; i < maxMessages; i++) { NotificationInfo info = mostRecentNotifPerThread.get(i); inboxStyle.addLine(info.formatInboxMessage(context)); } notification = inboxStyle.build(); uniqueThreads.clear(); mostRecentNotifPerThread.clear(); if (DEBUG) { Log.d(TAG, "updateNotification: multi messages," + " showing inboxStyle notification"); } } } notifyUserIfFullScreen(context, title); nm.notify(NOTIFICATION_ID, notification); // Trigger the QuickMessage pop-up activity if enabled // But don't show the QuickMessage if the user is in a call or the phone is ringing if (qmPopupEnabled && qmIntent != null) { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); if (tm.getCallState() == TelephonyManager.CALL_STATE_IDLE && !ConversationList.mIsRunning && !ComposeMessageActivity.mIsRunning) { context.startActivity(qmIntent); } } }