List of usage examples for android.app Notification PRIORITY_HIGH
int PRIORITY_HIGH
To view the source code for android.app Notification PRIORITY_HIGH.
Click Source Link
From source file:com.mishiranu.dashchan.content.service.PostingService.java
@Override public void onSendPostSuccess(String key, ChanPerformer.SendPostData data, String chanName, String threadNumber, String postNumber) {//w ww .j a v a 2 s . c om if (removeTask(key)) { String targetThreadNumber = data.threadNumber != null ? data.threadNumber : StringUtils.nullIfEmpty(threadNumber); if (targetThreadNumber != null && Preferences.isFavoriteOnReply()) { FavoritesStorage.getInstance().add(chanName, data.boardName, targetThreadNumber, null, 0); } StatisticsStorage.getInstance().incrementPostsSent(chanName, data.threadNumber == null); DraftsStorage draftsStorage = DraftsStorage.getInstance(); draftsStorage.removeCaptchaDraft(); draftsStorage.removePostDraft(chanName, data.boardName, data.threadNumber); if (targetThreadNumber != null) { String password = Preferences.getPassword(chanName); if (StringUtils.equals(password, data.password)) { password = null; } draftsStorage .store(new DraftsStorage.PostDraft(chanName, data.boardName, targetThreadNumber, data.name, data.email, password, data.optionSage, data.optionOriginalPoster, data.userIcon)); } if (targetThreadNumber != null) { postNumber = StringUtils.nullIfEmpty(postNumber); String comment = data.comment; if (comment != null) { CommentEditor commentEditor = ChanMarkup.get(chanName).safe() .obtainCommentEditor(data.boardName); if (commentEditor != null) { comment = commentEditor.removeTags(comment); } } NewPostData newPostData = new NewPostData(chanName, data.boardName, targetThreadNumber, postNumber, comment, data.threadNumber == null); String arrayKey = makeKey(chanName, data.boardName, targetThreadNumber); ArrayList<NewPostData> newPostDatas = NEW_POST_DATAS.get(arrayKey); if (newPostDatas == null) { newPostDatas = new ArrayList<>(1); NEW_POST_DATAS.put(arrayKey, newPostDatas); } newPostDatas.add(newPostData); if (newPostData.newThread) { PostingService.newThreadData = newPostData; PostingService.newThreadDataKey = makeKey(chanName, data.boardName, null); } Notification.Builder builder = new Notification.Builder(this); builder.setSmallIcon(android.R.drawable.stat_sys_upload_done); if (C.API_LOLLIPOP) { setNotificationColor(builder); builder.setPriority(Notification.PRIORITY_HIGH); builder.setVibrate(new long[0]); } else { builder.setTicker(getString(R.string.text_post_sent)); } builder.setContentTitle(getString(R.string.text_post_sent)); builder.setContentText( buildNotificationText(chanName, data.boardName, targetThreadNumber, postNumber)); String tag = newPostData.getNotificationTag(); Intent intent = NavigationUtils.obtainPostsIntent(this, chanName, data.boardName, targetThreadNumber, postNumber, null, 0); builder.setContentIntent( PendingIntent.getActivity(this, tag.hashCode(), intent, PendingIntent.FLAG_UPDATE_CURRENT)); notificationManager.notify(tag, 0, builder.build()); } ArrayList<Callback> callbacks = this.callbacks.get(key); if (callbacks != null) { for (Callback callback : callbacks) { callback.onSendPostSuccess(); } } LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(C.ACTION_POST_SENT)); } }
From source file:com.example.android.wearable.wear.wearnotifications.StandaloneMainActivity.java
private void generateBigPictureStyleNotification() { Log.d(TAG, "generateBigPictureStyleNotification()"); // Main steps for building a BIG_PICTURE_STYLE notification: // 0. Get your data // 1. Build the BIG_PICTURE_STYLE // 2. Set up main Intent for notification // 3. Set up RemoteInput, so users can input (keyboard and voice) from notification // 4. Build and issue the notification // 0. Get your data (everything unique per Notification) MockDatabase.BigPictureStyleSocialAppData bigPictureStyleSocialAppData = MockDatabase .getBigPictureStyleData();/*from ww w. j a v a2 s .c o m*/ // 1. Build the BIG_PICTURE_STYLE BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle() // Provides the bitmap for the BigPicture notification .bigPicture( BitmapFactory.decodeResource(getResources(), bigPictureStyleSocialAppData.getBigImage())) // Overrides ContentTitle in the big form of the template .setBigContentTitle(bigPictureStyleSocialAppData.getBigContentTitle()) // Summary line after the detail section in the big form of the template .setSummaryText(bigPictureStyleSocialAppData.getSummaryText()); // 2. Set up main Intent for notification Intent mainIntent = new Intent(this, BigPictureSocialMainActivity.class); PendingIntent mainPendingIntent = PendingIntent.getActivity(this, 0, mainIntent, PendingIntent.FLAG_UPDATE_CURRENT); // 3. Set up a RemoteInput Action, so users can input (keyboard, drawing, voice) directly // from the notification without entering the app. // Create the RemoteInput. String replyLabel = getString(R.string.reply_label); RemoteInput remoteInput = new RemoteInput.Builder(BigPictureSocialIntentService.EXTRA_COMMENT) .setLabel(replyLabel) // List of quick response choices for any wearables paired with the phone .setChoices(bigPictureStyleSocialAppData.getPossiblePostResponses()).build(); // Create PendingIntent for service that handles input. Intent replyIntent = new Intent(this, BigPictureSocialIntentService.class); replyIntent.setAction(BigPictureSocialIntentService.ACTION_COMMENT); PendingIntent replyActionPendingIntent = PendingIntent.getService(this, 0, replyIntent, 0); // Enable action to appear inline on Wear 2.0 (24+). This means it will appear over the // lower portion of the Notification for easy action (only possible for one action). final NotificationCompat.Action.WearableExtender inlineActionForWear2 = new NotificationCompat.Action.WearableExtender() .setHintDisplayActionInline(true).setHintLaunchesActivity(false); NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder( R.drawable.ic_reply_white_18dp, replyLabel, replyActionPendingIntent).addRemoteInput(remoteInput) // Add WearableExtender to enable inline actions .extend(inlineActionForWear2).build(); // 4. Build and issue the notification // Because we want this to be a new notification (not updating a previous notification), we // create a new Builder. Later, we use the same global builder to get back the notification // we built here for a comment on the post. NotificationCompat.Builder notificationCompatBuilder = new NotificationCompat.Builder( getApplicationContext()); GlobalNotificationBuilder.setNotificationCompatBuilderInstance(notificationCompatBuilder); // Build notification notificationCompatBuilder // BIG_PICTURE_STYLE sets title and content .setStyle(bigPictureStyle).setContentTitle(bigPictureStyleSocialAppData.getContentTitle()) .setContentText(bigPictureStyleSocialAppData.getContentText()).setSmallIcon(R.drawable.ic_launcher) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_person_black_48dp)) .setContentIntent(mainPendingIntent) // Set primary color (important for Wear 2.0 Notifications) .setColor(getResources().getColor(R.color.colorPrimary)) .setSubText(Integer.toString(1)).addAction(replyAction).setCategory(Notification.CATEGORY_SOCIAL) .setPriority(Notification.PRIORITY_HIGH) // Hides content on the lock-screen .setVisibility(Notification.VISIBILITY_PRIVATE) // Notifies system that the main launch intent is an Activity. .extend(new NotificationCompat.WearableExtender().setHintContentIntentLaunchesActivity(true)); // If the phone is in "Do not disturb mode, the user will still be notified if // the sender(s) is starred as a favorite. for (String name : bigPictureStyleSocialAppData.getParticipants()) { notificationCompatBuilder.addPerson(name); } Notification notification = notificationCompatBuilder.build(); mNotificationManagerCompat.notify(NOTIFICATION_ID, notification); // Close app to demonstrate notification in steam. finish(); }
From source file:com.example.android.wearable.wear.wearnotifications.MainActivity.java
private void generateBigPictureStyleNotification() { Log.d(TAG, "generateBigPictureStyleNotification()"); // Main steps for building a BIG_PICTURE_STYLE notification: // 0. Get your data // 1. Build the BIG_PICTURE_STYLE // 2. Set up main Intent for notification // 3. Set up RemoteInput, so users can input (keyboard and voice) from notification // 4. Build and issue the notification // 0. Get your data (everything unique per Notification) MockDatabase.BigPictureStyleSocialAppData bigPictureStyleSocialAppData = MockDatabase .getBigPictureStyleData();//from w w w . ja va 2 s .c o m // 1. Build the BIG_PICTURE_STYLE BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle() // Provides the bitmap for the BigPicture notification .bigPicture( BitmapFactory.decodeResource(getResources(), bigPictureStyleSocialAppData.getBigImage())) // Overrides ContentTitle in the big form of the template .setBigContentTitle(bigPictureStyleSocialAppData.getBigContentTitle()) // Summary line after the detail section in the big form of the template .setSummaryText(bigPictureStyleSocialAppData.getSummaryText()); // 2. Set up main Intent for notification Intent mainIntent = new Intent(this, BigPictureSocialMainActivity.class); // When creating your Intent, you need to take into account the back state, i.e., what // happens after your Activity launches and the user presses the back button. // There are two options: // 1. Regular activity - You're starting an Activity that's part of the application's // normal workflow. // 2. Special activity - The user only sees this Activity if it's started from a // notification. In a sense, the Activity extends the notification by providing // information that would be hard to display in the notification itself. // Even though this sample's MainActivity doesn't link to the Activity this Notification // launches directly, i.e., it isn't part of the normal workflow, a social app generally // always links to individual posts as part of the app flow, so we will follow option 1. // For an example of option 2, check out the BIG_TEXT_STYLE example. // For more information, check out our dev article: // https://developer.android.com/training/notify-user/navigation.html TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Adds the back stack stackBuilder.addParentStack(BigPictureSocialMainActivity.class); // Adds the Intent to the top of the stack stackBuilder.addNextIntent(mainIntent); // Gets a PendingIntent containing the entire back stack PendingIntent mainPendingIntent = PendingIntent.getActivity(this, 0, mainIntent, PendingIntent.FLAG_UPDATE_CURRENT); // 3. Set up RemoteInput, so users can input (keyboard and voice) from notification // Note: For API <24 (M and below) we need to use an Activity, so the lock-screen presents // the auth challenge. For API 24+ (N and above), we use a Service (could be a // BroadcastReceiver), so the user can input from Notification or lock-screen (they have // choice to allow) without leaving the notification. // Create the RemoteInput String replyLabel = getString(R.string.reply_label); RemoteInput remoteInput = new RemoteInput.Builder(BigPictureSocialIntentService.EXTRA_COMMENT) .setLabel(replyLabel) // List of quick response choices for any wearables paired with the phone .setChoices(bigPictureStyleSocialAppData.getPossiblePostResponses()).build(); // Pending intent = // API <24 (M and below): activity so the lock-screen presents the auth challenge // API 24+ (N and above): this should be a Service or BroadcastReceiver PendingIntent replyActionPendingIntent; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { Intent intent = new Intent(this, BigPictureSocialIntentService.class); intent.setAction(BigPictureSocialIntentService.ACTION_COMMENT); replyActionPendingIntent = PendingIntent.getService(this, 0, intent, 0); } else { replyActionPendingIntent = mainPendingIntent; } NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder( R.drawable.ic_reply_white_18dp, replyLabel, replyActionPendingIntent).addRemoteInput(remoteInput) .build(); // 4. Build and issue the notification // Because we want this to be a new notification (not updating a previous notification), we // create a new Builder. Later, we use the same global builder to get back the notification // we built here for a comment on the post. NotificationCompat.Builder notificationCompatBuilder = new NotificationCompat.Builder( getApplicationContext()); GlobalNotificationBuilder.setNotificationCompatBuilderInstance(notificationCompatBuilder); // 4. Build and issue the notification notificationCompatBuilder // BIG_PICTURE_STYLE sets title and content for API 16 (4.1 and after) .setStyle(bigPictureStyle) // Title for API <16 (4.0 and below) devices .setContentTitle(bigPictureStyleSocialAppData.getContentTitle()) // Content for API <24 (7.0 and below) devices .setContentText(bigPictureStyleSocialAppData.getContentText()).setSmallIcon(R.drawable.ic_launcher) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_person_black_48dp)) .setContentIntent(mainPendingIntent) // Set primary color (important for Wear 2.0 Notifications) .setColor(getResources().getColor(R.color.colorPrimary)) // SIDE NOTE: Auto-bundling is enabled for 4 or more notifications on API 24+ (N+) // devices and all Android Wear devices. If you have more than one notification and // you prefer a different summary notification, set a group key and create a // summary notification via // .setGroupSummary(true) // .setGroup(GROUP_KEY_YOUR_NAME_HERE) .setSubText(Integer.toString(1)).addAction(replyAction).setCategory(Notification.CATEGORY_SOCIAL) .setPriority(Notification.PRIORITY_HIGH) // Hides content on the lock-screen .setVisibility(Notification.VISIBILITY_PRIVATE); // If the phone is in "Do not disturb mode, the user will still be notified if // the sender(s) is starred as a favorite. for (String name : bigPictureStyleSocialAppData.getParticipants()) { notificationCompatBuilder.addPerson(name); } Notification notification = notificationCompatBuilder.build(); mNotificationManagerCompat.notify(NOTIFICATION_ID, notification); }
From source file:com.example.android.wearable.wear.wearnotifications.StandaloneMainActivity.java
private void generateInboxStyleNotification() { Log.d(TAG, "generateInboxStyleNotification()"); // Main steps for building a INBOX_STYLE notification: // 0. Get your data // 1. Build the INBOX_STYLE // 2. Set up main Intent for notification // 3. Build and issue the notification // 0. Get your data (everything unique per Notification) MockDatabase.InboxStyleEmailAppData inboxStyleEmailAppData = MockDatabase.getInboxStyleData(); // 1. Build the INBOX_STYLE InboxStyle inboxStyle = new NotificationCompat.InboxStyle() // This title is slightly different than regular title, since I know INBOX_STYLE is // available. .setBigContentTitle(inboxStyleEmailAppData.getBigContentTitle()) .setSummaryText(inboxStyleEmailAppData.getSummaryText()); // Add each summary line of the new emails, you can add up to 5 for (String summary : inboxStyleEmailAppData.getIndividualEmailSummary()) { inboxStyle.addLine(summary);/*from w w w .j a v a 2 s . c o m*/ } // 2. Set up main Intent for notification Intent mainIntent = new Intent(this, InboxMainActivity.class); PendingIntent mainPendingIntent = PendingIntent.getActivity(this, 0, mainIntent, PendingIntent.FLAG_UPDATE_CURRENT); // 3. Build and issue the notification // Because we want this to be a new notification (not updating a previous notification), we // create a new Builder. However, we don't need to update this notification later, so we // will not need to set a global builder for access to the notification later. NotificationCompat.Builder notificationCompatBuilder = new NotificationCompat.Builder( getApplicationContext()); GlobalNotificationBuilder.setNotificationCompatBuilderInstance(notificationCompatBuilder); // 4. Build and issue the notification notificationCompatBuilder // INBOX_STYLE sets title and content .setStyle(inboxStyle).setContentTitle(inboxStyleEmailAppData.getContentTitle()) .setContentText(inboxStyleEmailAppData.getContentText()).setSmallIcon(R.drawable.ic_launcher) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_person_black_48dp)) .setContentIntent(mainPendingIntent) // Set primary color (important for Wear 2.0 Notifications) .setColor(getResources().getColor(R.color.colorPrimary)) // Sets large number at the right-hand side of the notification for Wear 1.+. .setSubText(Integer.toString(inboxStyleEmailAppData.getNumberOfNewEmails())) .setCategory(Notification.CATEGORY_EMAIL).setPriority(Notification.PRIORITY_HIGH) // Hides content on the lock-screen .setVisibility(Notification.VISIBILITY_PRIVATE) // Notifies system that the main launch intent is an Activity. .extend(new NotificationCompat.WearableExtender().setHintContentIntentLaunchesActivity(true)); // If the phone is in "Do not disturb mode, the user will still be notified if // the sender(s) is starred as a favorite. for (String name : inboxStyleEmailAppData.getParticipants()) { notificationCompatBuilder.addPerson(name); } Notification notification = notificationCompatBuilder.build(); mNotificationManagerCompat.notify(NOTIFICATION_ID, notification); // Close app to demonstrate notification in steam. finish(); }
From source file:com.marekscholtz.bluetify.utilities.BluetoothChatService.java
private void showNotification(Friend friend, ChatMessage chatMessage) { if (mHandler == null) { Intent clickIntent = new Intent(getApplicationContext(), ChatActivity.class); clickIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); clickIntent.putExtra("mac_address", friend.getMacAddress()); PendingIntent clickPendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getApplicationContext()) .setSmallIcon(R.drawable.ic_logo_white_24dp).setPriority(Notification.PRIORITY_HIGH) .setColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary)) .setContentTitle(friend.getName()).setContentIntent(clickPendingIntent).setAutoCancel(true); if (mSharedPreferences.getBoolean("notification_sound", false)) { notificationBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI); }/*from w w w . ja va2s.c o m*/ if (mSharedPreferences.getBoolean("notification_vibration", false)) { notificationBuilder.setVibrate(new long[] { 0, 250, 250, 250 }); } if (mSharedPreferences.getBoolean("notification_light", false)) { notificationBuilder.setLights(0xff0082fc, 1000, 1000); } if (!chatMessage.hasPicture()) { notificationBuilder.setContentText(new String(chatMessage.getContent())); } else { if (chatMessage.isSent()) { notificationBuilder.setContentText( getApplicationContext().getResources().getString(R.string.you_sent_an_image) + "."); } else { notificationBuilder.setContentText(friend.getName() + " " + getApplicationContext().getResources().getString(R.string.sent_you_an_image) + "."); } } if (friend.getProfilePhoto() != null) { byte[] profilePhotoBytes = friend.getProfilePhoto(); Bitmap profilePhotoBitmap = BitmapFactory.decodeByteArray(friend.getProfilePhoto(), 0, profilePhotoBytes.length); notificationBuilder.setLargeIcon(profilePhotoBitmap); } //TODO reply in notification // if (android.os.Build.VERSION_CODES.N <= android.os.Build.VERSION.SDK_INT) { // PendingIntent replyPendingIntent = // PendingIntent.getActivity( // getApplicationContext(), // 0, // new Intent("REPLY"), // PendingIntent.FLAG_UPDATE_CURRENT // ); // RemoteInput remoteInput = new RemoteInput.Builder("message_text") // .setLabel(getString(R.string.write_a_message)) // .build(); // // NotificationCompat.Action action = new NotificationCompat.Action.Builder(R.drawable.ic_send_white_24dp, // getString(R.string.reply), replyPendingIntent) // .addRemoteInput(remoteInput) // .build(); // // getApplicationContext().registerReceiver(new NotificationBroadcastReceiver(), new IntentFilter("REPLY")); // notificationBuilder.addAction(action); // } NotificationManager mNotificationManager = (NotificationManager) getApplicationContext() .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(0, notificationBuilder.build()); } else { Vibrator vibrator = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(125); } }
From source file:com.example.android.wearable.wear.wearnotifications.MainActivity.java
private void generateInboxStyleNotification() { Log.d(TAG, "generateInboxStyleNotification()"); // Main steps for building a INBOX_STYLE notification: // 0. Get your data // 1. Build the INBOX_STYLE // 2. Set up main Intent for notification // 3. Build and issue the notification // 0. Get your data (everything unique per Notification) MockDatabase.InboxStyleEmailAppData inboxStyleEmailAppData = MockDatabase.getInboxStyleData(); // 1. Build the INBOX_STYLE InboxStyle inboxStyle = new NotificationCompat.InboxStyle() // This title is slightly different than regular title, since I know INBOX_STYLE is // available. .setBigContentTitle(inboxStyleEmailAppData.getBigContentTitle()) .setSummaryText(inboxStyleEmailAppData.getSummaryText()); // Add each summary line of the new emails, you can add up to 5 for (String summary : inboxStyleEmailAppData.getIndividualEmailSummary()) { inboxStyle.addLine(summary);/*from www. ja va2 s.com*/ } // 2. Set up main Intent for notification Intent mainIntent = new Intent(this, InboxMainActivity.class); // When creating your Intent, you need to take into account the back state, i.e., what // happens after your Activity launches and the user presses the back button. // There are two options: // 1. Regular activity - You're starting an Activity that's part of the application's // normal workflow. // 2. Special activity - The user only sees this Activity if it's started from a // notification. In a sense, the Activity extends the notification by providing // information that would be hard to display in the notification itself. // Even though this sample's MainActivity doesn't link to the Activity this Notification // launches directly, i.e., it isn't part of the normal workflow, a eamil app generally // always links to individual emails as part of the app flow, so we will follow option 1. // For an example of option 2, check out the BIG_TEXT_STYLE example. // For more information, check out our dev article: // https://developer.android.com/training/notify-user/navigation.html TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Adds the back stack stackBuilder.addParentStack(InboxMainActivity.class); // Adds the Intent to the top of the stack stackBuilder.addNextIntent(mainIntent); // Gets a PendingIntent containing the entire back stack PendingIntent mainPendingIntent = PendingIntent.getActivity(this, 0, mainIntent, PendingIntent.FLAG_UPDATE_CURRENT); // 3. Build and issue the notification // Because we want this to be a new notification (not updating a previous notification), we // create a new Builder. However, we don't need to update this notification later, so we // will not need to set a global builder for access to the notification later. NotificationCompat.Builder notificationCompatBuilder = new NotificationCompat.Builder( getApplicationContext()); GlobalNotificationBuilder.setNotificationCompatBuilderInstance(notificationCompatBuilder); // 4. Build and issue the notification notificationCompatBuilder // INBOX_STYLE sets title and content for API 16+ (4.1 and after) when the // notification is expanded .setStyle(inboxStyle) // Title for API <16 (4.0 and below) devices and API 16+ (4.1 and after) when the // notification is collapsed .setContentTitle(inboxStyleEmailAppData.getContentTitle()) // Content for API <24 (7.0 and below) devices and API 16+ (4.1 and after) when the // notification is collapsed .setContentText(inboxStyleEmailAppData.getContentText()).setSmallIcon(R.drawable.ic_launcher) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_person_black_48dp)) .setContentIntent(mainPendingIntent) // Set primary color (important for Wear 2.0 Notifications) .setColor(getResources().getColor(R.color.colorPrimary)) // SIDE NOTE: Auto-bundling is enabled for 4 or more notifications on API 24+ (N+) // devices and all Android Wear devices. If you have more than one notification and // you prefer a different summary notification, set a group key and create a // summary notification via // .setGroupSummary(true) // .setGroup(GROUP_KEY_YOUR_NAME_HERE) // Sets large number at the right-hand side of the notification for API <24 devices .setSubText(Integer.toString(inboxStyleEmailAppData.getNumberOfNewEmails())) .setCategory(Notification.CATEGORY_EMAIL).setPriority(Notification.PRIORITY_HIGH) // Hides content on the lock-screen .setVisibility(Notification.VISIBILITY_PRIVATE); // If the phone is in "Do not disturb mode, the user will still be notified if // the sender(s) is starred as a favorite. for (String name : inboxStyleEmailAppData.getParticipants()) { notificationCompatBuilder.addPerson(name); } Notification notification = notificationCompatBuilder.build(); mNotificationManagerCompat.notify(NOTIFICATION_ID, notification); }
From source file:com.example.android.wearable.wear.wearnotifications.StandaloneMainActivity.java
private void generateMessagingStyleNotification() { Log.d(TAG, "generateMessagingStyleNotification()"); // Main steps for building a MESSAGING_STYLE notification: // 0. Get your data // 1. Build the MESSAGING_STYLE // 2. Add support for Wear 1.+ // 3. Set up main Intent for notification // 4. Set up RemoteInput (users can input directly from notification) // 5. Build and issue the notification // 0. Get your data (everything unique per Notification) MockDatabase.MessagingStyleCommsAppData messagingStyleCommsAppData = MockDatabase.getMessagingStyleData(); // 1. Build the Notification.Style (MESSAGING_STYLE) String contentTitle = messagingStyleCommsAppData.getContentTitle(); MessagingStyle messagingStyle = new NotificationCompat.MessagingStyle( messagingStyleCommsAppData.getReplayName()) // You could set a different title to appear when the messaging style // is supported on device (24+) if you wish. In our case, we use the same // title. .setConversationTitle(contentTitle); // Adds all Messages // Note: Messages include the text, timestamp, and sender for (MessagingStyle.Message message : messagingStyleCommsAppData.getMessages()) { messagingStyle.addMessage(message); }/*from ww w . j a v a2 s .co m*/ // 2. Add support for Wear 1.+ // Since Wear 1.0 doesn't support the MESSAGING_STYLE, we use the BIG_TEXT_STYLE, so all the // text is visible. // This is basically a toString() of all the Messages above. String fullMessageForWearVersion1 = messagingStyleCommsAppData.getFullConversation(); Notification chatHistoryForWearV1 = new NotificationCompat.Builder(getApplicationContext()) .setStyle(new BigTextStyle().bigText(fullMessageForWearVersion1)).setContentTitle(contentTitle) .setSmallIcon(R.drawable.ic_launcher).setContentText(fullMessageForWearVersion1).build(); // Adds page with all text to support Wear 1.+. NotificationCompat.WearableExtender wearableExtenderForWearVersion1 = new NotificationCompat.WearableExtender() .setHintContentIntentLaunchesActivity(true).addPage(chatHistoryForWearV1); // 3. Set up main Intent for notification Intent notifyIntent = new Intent(this, MessagingMainActivity.class); PendingIntent mainPendingIntent = PendingIntent.getActivity(this, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT); // 4. Set up a RemoteInput Action, so users can input (keyboard, drawing, voice) directly // from the notification without entering the app. // Create the RemoteInput specifying this key. String replyLabel = getString(R.string.reply_label); RemoteInput remoteInput = new RemoteInput.Builder(MessagingIntentService.EXTRA_REPLY).setLabel(replyLabel) .build(); // Create PendingIntent for service that handles input. Intent replyIntent = new Intent(this, MessagingIntentService.class); replyIntent.setAction(MessagingIntentService.ACTION_REPLY); PendingIntent replyActionPendingIntent = PendingIntent.getService(this, 0, replyIntent, 0); // Enable action to appear inline on Wear 2.0 (24+). This means it will appear over the // lower portion of the Notification for easy action (only possible for one action). final NotificationCompat.Action.WearableExtender inlineActionForWear2 = new NotificationCompat.Action.WearableExtender() .setHintDisplayActionInline(true).setHintLaunchesActivity(false); NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder( R.drawable.ic_reply_white_18dp, replyLabel, replyActionPendingIntent).addRemoteInput(remoteInput) // Allows system to generate replies by context of conversation .setAllowGeneratedReplies(true) // Add WearableExtender to enable inline actions .extend(inlineActionForWear2).build(); // 5. Build and issue the notification // Because we want this to be a new notification (not updating current notification), we // create a new Builder. Later, we update this same notification, so we need to save this // Builder globally (as outlined earlier). NotificationCompat.Builder notificationCompatBuilder = new NotificationCompat.Builder( getApplicationContext()); GlobalNotificationBuilder.setNotificationCompatBuilderInstance(notificationCompatBuilder); // Builds and issues notification notificationCompatBuilder // MESSAGING_STYLE sets title and content for API 24+ (Wear 2.0) devices .setStyle(messagingStyle) // Title for API <24 (Wear 1.+) devices .setContentTitle(contentTitle) // Content for API <24 (Wear 1.+) devices .setContentText(messagingStyleCommsAppData.getContentText()).setSmallIcon(R.drawable.ic_launcher) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_person_black_48dp)) .setContentIntent(mainPendingIntent) // Set primary color (important for Wear 2.0 Notifications) .setColor(getResources().getColor(R.color.colorPrimary)) // Number of new notifications for API <24 (Wear 1.+) devices .setSubText(Integer.toString(messagingStyleCommsAppData.getNumberOfNewMessages())) .addAction(replyAction).setCategory(Notification.CATEGORY_MESSAGE) .setPriority(Notification.PRIORITY_HIGH) // Hides content on the lock-screen .setVisibility(Notification.VISIBILITY_PRIVATE) // Adds multiple pages for easy consumption on a wear device. .extend(wearableExtenderForWearVersion1); // If the phone is in "Do not disturb mode, the user will still be notified if // the sender(s) is starred as a favorite. for (String name : messagingStyleCommsAppData.getParticipants()) { notificationCompatBuilder.addPerson(name); } Notification notification = notificationCompatBuilder.build(); mNotificationManagerCompat.notify(NOTIFICATION_ID, notification); // Close app to demonstrate notification in steam. finish(); }
From source file:com.android.dragonkeyboardfirmwareupdater.KeyboardFirmwareUpdateService.java
private void showBatteryWarningNotification() { Log.d(TAG, "showBatteryWarningNotification: " + getKeyboardString()); Notification batteryWarningNotification = new NotificationCompat.Builder(this) .setContentTitle(getString(R.string.notification_battery_warning_title)) .setContentText(getString(R.string.notification_battery_warning_text)) .setSmallIcon(R.drawable.ic_battery_warning).setAutoCancel(true).setOnlyAlertOnce(true) .setPriority(Notification.PRIORITY_HIGH).setColor(Color.RED) .setStyle(new NotificationCompat.BigTextStyle() .bigText(getString(R.string.notification_battery_warning_text))) .build();//from w ww. ja va2 s . c o m // Show the notification via notification manager NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(BATTERY_WARNING_NOTIFICATION_ID, batteryWarningNotification); }
From source file:com.android.calendar.alerts.AlertService.java
private static void postNotification(NotificationInfo info, String summaryText, Context context, boolean highPriority, NotificationPrefs prefs, NotificationMgr notificationMgr, int notificationId) { int priorityVal = Notification.PRIORITY_DEFAULT; if (highPriority) { priorityVal = Notification.PRIORITY_HIGH; }/*from w w w.ja va 2s . co m*/ String tickerText = getTickerText(info.eventName, info.location); NotificationWrapper notification = AlertReceiver.makeExpandingNotification(context, info.eventName, summaryText, info.description, info.startMillis, info.endMillis, info.eventId, notificationId, prefs.getDoPopup(), priorityVal); boolean quietUpdate = true; String ringtone = NotificationPrefs.EMPTY_RINGTONE; if (info.newAlert) { quietUpdate = prefs.quietUpdate; // If we've already played a ringtone, don't play any more sounds so only // 1 sound per group of notifications. ringtone = prefs.getRingtoneAndSilence(); } addNotificationOptions(notification, quietUpdate, tickerText, prefs.getDefaultVibrate(), ringtone, true); /* Show the LED for these non-expired events */ // Post the notification. notificationMgr.notify(notificationId, notification); if (DEBUG) { Log.d(TAG, "Posting individual alarm notification, eventId:" + info.eventId + ", notificationId:" + notificationId + (TextUtils.isEmpty(ringtone) ? ", quiet" : ", LOUD") + (highPriority ? ", high-priority" : "")); } }
From source file:com.example.android.wearable.wear.wearnotifications.MainActivity.java
private void generateMessagingStyleNotification() { Log.d(TAG, "generateMessagingStyleNotification()"); // Main steps for building a MESSAGING_STYLE notification: // 0. Get your data // 1. Build the MESSAGING_STYLE // 2. Add support for Wear 1.+ // 3. Set up main Intent for notification // 4. Set up RemoteInput (users can input directly from notification) // 5. Build and issue the notification // 0. Get your data (everything unique per Notification) MockDatabase.MessagingStyleCommsAppData messagingStyleCommsAppData = MockDatabase.getMessagingStyleData(); // 1. Build the Notification.Style (MESSAGING_STYLE) String contentTitle = messagingStyleCommsAppData.getContentTitle(); MessagingStyle messagingStyle = new NotificationCompat.MessagingStyle( messagingStyleCommsAppData.getReplayName()) // You could set a different title to appear when the messaging style // is supported on device (24+) if you wish. In our case, we use the same // title. .setConversationTitle(contentTitle); // Adds all Messages // Note: Messages include the text, timestamp, and sender for (MessagingStyle.Message message : messagingStyleCommsAppData.getMessages()) { messagingStyle.addMessage(message); }//from w w w .ja v a 2 s. c om // 2. Add support for Wear 1.+ // Since Wear 1.0 doesn't support the MESSAGING_STYLE, we use the BIG_TEXT_STYLE, so all the // text is visible. // This is basically a toString() of all the Messages above. String fullMessageForWearVersion1 = messagingStyleCommsAppData.getFullConversation(); Notification chatHistoryForWearV1 = new NotificationCompat.Builder(getApplicationContext()) .setStyle(new BigTextStyle().bigText(fullMessageForWearVersion1)).setContentTitle(contentTitle) .setSmallIcon(R.drawable.ic_launcher).setContentText(fullMessageForWearVersion1).build(); // Adds page with all text to support Wear 1.+. NotificationCompat.WearableExtender wearableExtenderForWearVersion1 = new NotificationCompat.WearableExtender() .addPage(chatHistoryForWearV1); // 3. Set up main Intent for notification Intent notifyIntent = new Intent(this, MessagingMainActivity.class); // When creating your Intent, you need to take into account the back state, i.e., what // happens after your Activity launches and the user presses the back button. // There are two options: // 1. Regular activity - You're starting an Activity that's part of the application's // normal workflow. // 2. Special activity - The user only sees this Activity if it's started from a // notification. In a sense, the Activity extends the notification by providing // information that would be hard to display in the notification itself. // Even though this sample's MainActivity doesn't link to the Activity this Notification // launches directly, i.e., it isn't part of the normal workflow, a chat app generally // always links to individual conversations as part of the app flow, so we will follow // option 1. // For an example of option 2, check out the BIG_TEXT_STYLE example. // For more information, check out our dev article: // https://developer.android.com/training/notify-user/navigation.html TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Adds the back stack stackBuilder.addParentStack(MessagingMainActivity.class); // Adds the Intent to the top of the stack stackBuilder.addNextIntent(notifyIntent); // Gets a PendingIntent containing the entire back stack PendingIntent mainPendingIntent = PendingIntent.getActivity(this, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT); // 4. Set up RemoteInput, so users can input (keyboard and voice) from notification // Note: For API <24 (M and below) we need to use an Activity, so the lock-screen present // the auth challenge. For API 24+ (N and above), we use a Service (could be a // BroadcastReceiver), so the user can input from Notification or lock-screen (they have // choice to allow) without leaving the notification. // Create the RemoteInput specifying this key String replyLabel = getString(R.string.reply_label); RemoteInput remoteInput = new RemoteInput.Builder(MessagingIntentService.EXTRA_REPLY).setLabel(replyLabel) .build(); // Pending intent = // API <24 (M and below): activity so the lock-screen presents the auth challenge // API 24+ (N and above): this should be a Service or BroadcastReceiver PendingIntent replyActionPendingIntent; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { Intent intent = new Intent(this, MessagingIntentService.class); intent.setAction(MessagingIntentService.ACTION_REPLY); replyActionPendingIntent = PendingIntent.getService(this, 0, intent, 0); } else { replyActionPendingIntent = mainPendingIntent; } NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder( R.drawable.ic_reply_white_18dp, replyLabel, replyActionPendingIntent).addRemoteInput(remoteInput) // Allows system to generate replies by context of conversation .setAllowGeneratedReplies(true).build(); // 5. Build and issue the notification // Because we want this to be a new notification (not updating current notification), we // create a new Builder. Later, we update this same notification, so we need to save this // Builder globally (as outlined earlier). NotificationCompat.Builder notificationCompatBuilder = new NotificationCompat.Builder( getApplicationContext()); GlobalNotificationBuilder.setNotificationCompatBuilderInstance(notificationCompatBuilder); // Builds and issues notification notificationCompatBuilder // MESSAGING_STYLE sets title and content for API 24+ (N and above) devices .setStyle(messagingStyle) // Title for API <24 (M and below) devices .setContentTitle(contentTitle) // Content for API <24 (M and below) devices .setContentText(messagingStyleCommsAppData.getContentText()).setSmallIcon(R.drawable.ic_launcher) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_person_black_48dp)) .setContentIntent(mainPendingIntent) // Set primary color (important for Wear 2.0 Notifications) .setColor(getResources().getColor(R.color.colorPrimary)) // SIDE NOTE: Auto-bundling is enabled for 4 or more notifications on API 24+ (N+) // devices and all Android Wear devices. If you have more than one notification and // you prefer a different summary notification, set a group key and create a // summary notification via // .setGroupSummary(true) // .setGroup(GROUP_KEY_YOUR_NAME_HERE) // Number of new notifications for API <24 (M and below) devices .setSubText(Integer.toString(messagingStyleCommsAppData.getNumberOfNewMessages())) .addAction(replyAction).setCategory(Notification.CATEGORY_MESSAGE) .setPriority(Notification.PRIORITY_HIGH) // Hides content on the lock-screen .setVisibility(Notification.VISIBILITY_PRIVATE) // Adds multiple pages for easy consumption on a wear device. .extend(wearableExtenderForWearVersion1); // If the phone is in "Do not disturb mode, the user will still be notified if // the sender(s) is starred as a favorite. for (String name : messagingStyleCommsAppData.getParticipants()) { notificationCompatBuilder.addPerson(name); } Notification notification = notificationCompatBuilder.build(); mNotificationManagerCompat.notify(NOTIFICATION_ID, notification); }