List of usage examples for android.app Notification CATEGORY_EMAIL
String CATEGORY_EMAIL
To view the source code for android.app Notification CATEGORY_EMAIL.
Click Source Link
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 .jav a2 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.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 w w w . jav a2 s .c o m*/ } // 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); }