androidx.core.app.NotificationCompat.MessagingStyle Java Examples
The following examples show how to use
androidx.core.app.NotificationCompat.MessagingStyle.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MessagingIntentService.java From wear-os-samples with Apache License 2.0 | 4 votes |
/** Handles action for replying to messages from the notification. */ private void handleActionReply(CharSequence replyCharSequence) { Log.d(TAG, "handleActionReply(): " + replyCharSequence); if (replyCharSequence != null) { // TODO: Asynchronously save your message to Database and servers. /* * You have two options for updating your notification (this class uses approach #2): * * 1. Use a new NotificationCompatBuilder to create the Notification. This approach * requires you to get *ALL* the information that existed in the previous * Notification (and updates) and pass it to the builder. This is the approach used in * the MainActivity. * * 2. Use the original NotificationCompatBuilder to create the Notification. This * approach requires you to store a reference to the original builder. The benefit is * you only need the new/updated information. In our case, the reply from the user * which we already have here. * * IMPORTANT NOTE: You shouldn't save/modify the resulting Notification object using * its member variables and/or legacy APIs. If you want to retain anything from update * to update, retain the Builder as option 2 outlines. */ // Retrieves NotificationCompat.Builder used to create initial Notification NotificationCompat.Builder notificationCompatBuilder = GlobalNotificationBuilder.getNotificationCompatBuilderInstance(); // Recreate builder from persistent state if app process is killed if (notificationCompatBuilder == null) { // Note: New builder set globally in the method notificationCompatBuilder = recreateBuilderWithMessagingStyle(); } // Since we are adding to the MessagingStyle, we need to first retrieve the // current MessagingStyle from the Notification itself. Notification notification = notificationCompatBuilder.build(); MessagingStyle messagingStyle = NotificationCompat.MessagingStyle.extractMessagingStyleFromNotification( notification); // Add new message to the MessagingStyle. Set last parameter to null for responses // from user. messagingStyle.addMessage(replyCharSequence, System.currentTimeMillis(), (Person) null); // Updates the Notification notification = notificationCompatBuilder.setStyle(messagingStyle).build(); // Pushes out the updated Notification NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(getApplicationContext()); notificationManagerCompat.notify(NotificationsActivity.NOTIFICATION_ID, notification); } }
Example #2
Source File: MockDatabase.java From wear-os-samples with Apache License 2.0 | 4 votes |
private MessagingStyleCommsAppData(Context context) { // Standard notification values: // Content for API <24 (M and below) devices. // Note: I am actually hardcoding these Strings based on info below. You would be // pulling these values from the same source in your database. I leave this up here, so // you can see the standard parts of a Notification first. mContentTitle = "3 Messages w/ Famous, Wendy"; mContentText = "HEY, I see my house! :)"; mPriority = NotificationCompat.PRIORITY_HIGH; // Create the users for the conversation. // Name preferred when replying to chat. mMe = new Person.Builder() .setName("Me MacDonald") .setKey("1234567890") .setUri("tel:1234567890") .setIcon( IconCompat.createWithResource(context, R.drawable.me_macdonald)) .build(); Person participant1 = new Person.Builder() .setName("Famous Fryer") .setKey("9876543210") .setUri("tel:9876543210") .setIcon( IconCompat.createWithResource(context, R.drawable.famous_fryer)) .build(); Person participant2 = new Person.Builder() .setName("Wendy Wonda") .setKey("2233221122") .setUri("tel:2233221122") .setIcon(IconCompat.createWithResource(context, R.drawable.wendy_wonda)) .build(); // If the phone is in "Do not disturb mode, the user will still be notified if // the user(s) is starred as a favorite. // Note: You don't need to add yourself, aka 'me', as a participant. mParticipants = new ArrayList<>(); mParticipants.add(participant1); mParticipants.add(participant2); mMessages = new ArrayList<>(); // For each message, you need the timestamp. In this case, we are using arbitrary longs // representing time in milliseconds. mMessages.add( // When you are setting an image for a message, text does not display. new MessagingStyle.Message("", 1528490641998L, participant1) .setData( "image/png", resourceToUri(context, R.drawable.earth))); mMessages.add( new MessagingStyle.Message( "Visiting the moon again? :P", 1528490643998L, mMe)); mMessages.add( new MessagingStyle.Message( "HEY, I see my house!", 1528490645998L, participant2)); // String version of the mMessages above. mFullConversation = "Famous: [Picture of Moon]\n\n" + "Me: Visiting the moon again? :P\n\n" + "Wendy: HEY, I see my house! :)\n\n"; // Responses based on the last messages of the conversation. You would use // Machine Learning to get these (https://developers.google.com/ml-kit/). mReplyChoicesBasedOnLastMessages = new CharSequence[] {"Me too!", "How's the weather?", "You have good eyesight."}; // Notification channel values (for devices targeting 26 and above): mChannelId = "channel_messaging_1"; // The user-visible name of the channel. mChannelName = "Sample Messaging"; // The user-visible description of the channel. mChannelDescription = "Sample Messaging Notifications"; mChannelImportance = NotificationManager.IMPORTANCE_MAX; mChannelEnableVibrate = true; mChannelLockscreenVisibility = NotificationCompat.VISIBILITY_PRIVATE; }
Example #3
Source File: MockDatabase.java From wear-os-samples with Apache License 2.0 | 4 votes |
public ArrayList<MessagingStyle.Message> getMessages() { return mMessages; }
Example #4
Source File: MockDatabase.java From user-interface-samples with Apache License 2.0 | 4 votes |
private MessagingStyleCommsAppData(Context context) { // Standard notification values: // Content for API <24 (M and below) devices. // Note: I am actually hardcoding these Strings based on info below. You would be // pulling these values from the same source in your database. I leave this up here, so // you can see the standard parts of a Notification first. mContentTitle = "3 Messages w/ Famous, Wendy"; mContentText = "HEY, I see my house! :)"; mPriority = NotificationCompat.PRIORITY_HIGH; // Create the users for the conversation. // Name preferred when replying to chat. mMe = new Person.Builder() .setName("Me MacDonald") .setKey("1234567890") .setUri("tel:1234567890") .setIcon( IconCompat.createWithResource(context, R.drawable.me_macdonald)) .build(); Person participant1 = new Person.Builder() .setName("Famous Frank") .setKey("9876543210") .setUri("tel:9876543210") .setIcon( IconCompat.createWithResource(context, R.drawable.famous_fryer)) .build(); Person participant2 = new Person.Builder() .setName("Wendy Weather") .setKey("2233221122") .setUri("tel:2233221122") .setIcon(IconCompat.createWithResource(context, R.drawable.wendy_wonda)) .build(); // If the phone is in "Do not disturb mode, the user will still be notified if // the user(s) is starred as a favorite. // Note: You don't need to add yourself, aka 'me', as a participant. mParticipants = new ArrayList<>(); mParticipants.add(participant1); mParticipants.add(participant2); mMessages = new ArrayList<>(); // For each message, you need the timestamp. In this case, we are using arbitrary longs // representing time in milliseconds. mMessages.add( // When you are setting an image for a message, text does not display. new MessagingStyle.Message("", 1528490641998l, participant1) .setData("image/png", resourceToUri(context, R.drawable.earth))); mMessages.add( new MessagingStyle.Message( "Visiting the moon again? :P", 1528490643998l, mMe)); mMessages.add( new MessagingStyle.Message("HEY, I see my house!", 1528490645998l, participant2)); // String version of the mMessages above. mFullConversation = "Famous: [Picture of Moon]\n\n" + "Me: Visiting the moon again? :P\n\n" + "Wendy: HEY, I see my house! :)\n\n"; // Responses based on the last messages of the conversation. You would use // Machine Learning to get these (https://developers.google.com/ml-kit/). mReplyChoicesBasedOnLastMessages = new CharSequence[] {"Me too!", "How's the weather?", "You have good eyesight."}; // Notification channel values (for devices targeting 26 and above): mChannelId = "channel_messaging_1"; // The user-visible name of the channel. mChannelName = "Sample Messaging"; // The user-visible description of the channel. mChannelDescription = "Sample Messaging Notifications"; mChannelImportance = NotificationManager.IMPORTANCE_MAX; mChannelEnableVibrate = true; mChannelLockscreenVisibility = NotificationCompat.VISIBILITY_PRIVATE; }
Example #5
Source File: MockDatabase.java From user-interface-samples with Apache License 2.0 | 4 votes |
public ArrayList<MessagingStyle.Message> getMessages() { return mMessages; }
Example #6
Source File: MessagingIntentService.java From user-interface-samples with Apache License 2.0 | 4 votes |
/** Handles action for replying to messages from the notification. */ private void handleActionReply(CharSequence replyCharSequence) { Log.d(TAG, "handleActionReply(): " + replyCharSequence); if (replyCharSequence != null) { // TODO: Asynchronously save your message to Database and servers. /* * You have two options for updating your notification (this class uses approach #2): * * 1. Use a new NotificationCompatBuilder to create the Notification. This approach * requires you to get *ALL* the information that existed in the previous * Notification (and updates) and pass it to the builder. This is the approach used in * the MainActivity. * * 2. Use the original NotificationCompatBuilder to create the Notification. This * approach requires you to store a reference to the original builder. The benefit is * you only need the new/updated information. In our case, the reply from the user * which we already have here. * * IMPORTANT NOTE: You shouldn't save/modify the resulting Notification object using * its member variables and/or legacy APIs. If you want to retain anything from update * to update, retain the Builder as option 2 outlines. */ // Retrieves NotificationCompat.Builder used to create initial Notification NotificationCompat.Builder notificationCompatBuilder = GlobalNotificationBuilder.getNotificationCompatBuilderInstance(); // Recreate builder from persistent state if app process is killed if (notificationCompatBuilder == null) { // Note: New builder set globally in the method notificationCompatBuilder = recreateBuilderWithMessagingStyle(); } // Since we are adding to the MessagingStyle, we need to first retrieve the // current MessagingStyle from the Notification itself. Notification notification = notificationCompatBuilder.build(); MessagingStyle messagingStyle = NotificationCompat.MessagingStyle.extractMessagingStyleFromNotification( notification); // Add new message to the MessagingStyle. Set last parameter to null for responses // from user. messagingStyle.addMessage(replyCharSequence, System.currentTimeMillis(), (Person) null); // Updates the Notification notification = notificationCompatBuilder.setStyle(messagingStyle).build(); // Pushes out the updated Notification NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(getApplicationContext()); notificationManagerCompat.notify(StandaloneMainActivity.NOTIFICATION_ID, notification); } }
Example #7
Source File: MessagingIntentService.java From user-interface-samples with Apache License 2.0 | 4 votes |
/** Handles action for replying to messages from the notification. */ private void handleActionReply(CharSequence replyCharSequence) { Log.d(TAG, "handleActionReply(): " + replyCharSequence); if (replyCharSequence != null) { // TODO: Asynchronously save your message to Database and servers. /* * You have two options for updating your notification (this class uses approach #2): * * 1. Use a new NotificationCompatBuilder to create the Notification. This approach * requires you to get *ALL* the information that existed in the previous * Notification (and updates) and pass it to the builder. This is the approach used in * the MainActivity. * * 2. Use the original NotificationCompatBuilder to create the Notification. This * approach requires you to store a reference to the original builder. The benefit is * you only need the new/updated information. In our case, the reply from the user * which we already have here. * * IMPORTANT NOTE: You shouldn't save/modify the resulting Notification object using * its member variables and/or legacy APIs. If you want to retain anything from update * to update, retain the Builder as option 2 outlines. */ // Retrieves NotificationCompat.Builder used to create initial Notification NotificationCompat.Builder notificationCompatBuilder = GlobalNotificationBuilder.getNotificationCompatBuilderInstance(); // Recreate builder from persistent state if app process is killed if (notificationCompatBuilder == null) { // Note: New builder set globally in the method notificationCompatBuilder = recreateBuilderWithMessagingStyle(); } // Since we are adding to the MessagingStyle, we need to first retrieve the // current MessagingStyle from the Notification itself. Notification notification = notificationCompatBuilder.build(); MessagingStyle messagingStyle = NotificationCompat.MessagingStyle.extractMessagingStyleFromNotification( notification); // Add new message to the MessagingStyle. Set last parameter to null for responses // from user. messagingStyle.addMessage(replyCharSequence, System.currentTimeMillis(), (Person) null); // Updates the Notification notification = notificationCompatBuilder.setStyle(messagingStyle).build(); // Pushes out the updated Notification NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(getApplicationContext()); notificationManagerCompat.notify(MainActivity.NOTIFICATION_ID, notification); } }
Example #8
Source File: MockDatabase.java From android-Notifications with Apache License 2.0 | 4 votes |
private MessagingStyleCommsAppData(Context context) { // Standard notification values: // Content for API <24 (M and below) devices. // Note: I am actually hardcoding these Strings based on info below. You would be // pulling these values from the same source in your database. I leave this up here, so // you can see the standard parts of a Notification first. mContentTitle = "3 Messages w/ Famous, Wendy"; mContentText = "HEY, I see my house! :)"; mPriority = NotificationCompat.PRIORITY_HIGH; // Create the users for the conversation. // Name preferred when replying to chat. mMe = new Person.Builder() .setName("Me MacDonald") .setKey("1234567890") .setUri("tel:1234567890") .setIcon( IconCompat.createWithResource(context, R.drawable.me_macdonald)) .build(); Person participant1 = new Person.Builder() .setName("Famous Fryer") .setKey("9876543210") .setUri("tel:9876543210") .setIcon( IconCompat.createWithResource(context, R.drawable.famous_fryer)) .build(); Person participant2 = new Person.Builder() .setName("Wendy Wonda") .setKey("2233221122") .setUri("tel:2233221122") .setIcon(IconCompat.createWithResource(context, R.drawable.wendy_wonda)) .build(); // If the phone is in "Do not disturb mode, the user will still be notified if // the user(s) is starred as a favorite. // Note: You don't need to add yourself, aka 'me', as a participant. mParticipants = new ArrayList<>(); mParticipants.add(participant1); mParticipants.add(participant2); mMessages = new ArrayList<>(); // For each message, you need the timestamp. In this case, we are using arbitrary longs // representing time in milliseconds. mMessages.add( // When you are setting an image for a message, text does not display. new MessagingStyle.Message("", 1528490641998l, participant1) .setData("image/png", resourceToUri(context, R.drawable.earth))); mMessages.add( new MessagingStyle.Message( "Visiting the moon again? :P", 1528490643998l, mMe)); mMessages.add( new MessagingStyle.Message("HEY, I see my house!", 1528490645998l, participant2)); // String version of the mMessages above. mFullConversation = "Famous: [Picture of Moon]\n\n" + "Me: Visiting the moon again? :P\n\n" + "Wendy: HEY, I see my house! :)\n\n"; // Responses based on the last messages of the conversation. You would use // Machine Learning to get these (https://developers.google.com/ml-kit/). mReplyChoicesBasedOnLastMessages = new CharSequence[] {"Me too!", "How's the weather?", "You have good eyesight."}; // Notification channel values (for devices targeting 26 and above): mChannelId = "channel_messaging_1"; // The user-visible name of the channel. mChannelName = "Sample Messaging"; // The user-visible description of the channel. mChannelDescription = "Sample Messaging Notifications"; mChannelImportance = NotificationManager.IMPORTANCE_MAX; mChannelEnableVibrate = true; mChannelLockscreenVisibility = NotificationCompat.VISIBILITY_PRIVATE; }
Example #9
Source File: MockDatabase.java From android-Notifications with Apache License 2.0 | 4 votes |
public ArrayList<MessagingStyle.Message> getMessages() { return mMessages; }
Example #10
Source File: MessagingIntentService.java From android-Notifications with Apache License 2.0 | 4 votes |
/** Handles action for replying to messages from the notification. */ private void handleActionReply(CharSequence replyCharSequence) { Log.d(TAG, "handleActionReply(): " + replyCharSequence); if (replyCharSequence != null) { // TODO: Asynchronously save your message to Database and servers. /* * You have two options for updating your notification (this class uses approach #2): * * 1. Use a new NotificationCompatBuilder to create the Notification. This approach * requires you to get *ALL* the information that existed in the previous * Notification (and updates) and pass it to the builder. This is the approach used in * the MainActivity. * * 2. Use the original NotificationCompatBuilder to create the Notification. This * approach requires you to store a reference to the original builder. The benefit is * you only need the new/updated information. In our case, the reply from the user * which we already have here. * * IMPORTANT NOTE: You shouldn't save/modify the resulting Notification object using * its member variables and/or legacy APIs. If you want to retain anything from update * to update, retain the Builder as option 2 outlines. */ // Retrieves NotificationCompat.Builder used to create initial Notification NotificationCompat.Builder notificationCompatBuilder = GlobalNotificationBuilder.getNotificationCompatBuilderInstance(); // Recreate builder from persistent state if app process is killed if (notificationCompatBuilder == null) { // Note: New builder set globally in the method notificationCompatBuilder = recreateBuilderWithMessagingStyle(); } // Since we are adding to the MessagingStyle, we need to first retrieve the // current MessagingStyle from the Notification itself. Notification notification = notificationCompatBuilder.build(); MessagingStyle messagingStyle = NotificationCompat.MessagingStyle.extractMessagingStyleFromNotification( notification); // Add new message to the MessagingStyle. Set last parameter to null for responses // from user. messagingStyle.addMessage(replyCharSequence, System.currentTimeMillis(), (Person) null); // Updates the Notification notification = notificationCompatBuilder.setStyle(messagingStyle).build(); // Pushes out the updated Notification NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(getApplicationContext()); notificationManagerCompat.notify(StandaloneMainActivity.NOTIFICATION_ID, notification); } }
Example #11
Source File: MessagingIntentService.java From android-Notifications with Apache License 2.0 | 4 votes |
/** Handles action for replying to messages from the notification. */ private void handleActionReply(CharSequence replyCharSequence) { Log.d(TAG, "handleActionReply(): " + replyCharSequence); if (replyCharSequence != null) { // TODO: Asynchronously save your message to Database and servers. /* * You have two options for updating your notification (this class uses approach #2): * * 1. Use a new NotificationCompatBuilder to create the Notification. This approach * requires you to get *ALL* the information that existed in the previous * Notification (and updates) and pass it to the builder. This is the approach used in * the MainActivity. * * 2. Use the original NotificationCompatBuilder to create the Notification. This * approach requires you to store a reference to the original builder. The benefit is * you only need the new/updated information. In our case, the reply from the user * which we already have here. * * IMPORTANT NOTE: You shouldn't save/modify the resulting Notification object using * its member variables and/or legacy APIs. If you want to retain anything from update * to update, retain the Builder as option 2 outlines. */ // Retrieves NotificationCompat.Builder used to create initial Notification NotificationCompat.Builder notificationCompatBuilder = GlobalNotificationBuilder.getNotificationCompatBuilderInstance(); // Recreate builder from persistent state if app process is killed if (notificationCompatBuilder == null) { // Note: New builder set globally in the method notificationCompatBuilder = recreateBuilderWithMessagingStyle(); } // Since we are adding to the MessagingStyle, we need to first retrieve the // current MessagingStyle from the Notification itself. Notification notification = notificationCompatBuilder.build(); MessagingStyle messagingStyle = NotificationCompat.MessagingStyle.extractMessagingStyleFromNotification( notification); // Add new message to the MessagingStyle. Set last parameter to null for responses // from user. messagingStyle.addMessage(replyCharSequence, System.currentTimeMillis(), (Person) null); // Updates the Notification notification = notificationCompatBuilder.setStyle(messagingStyle).build(); // Pushes out the updated Notification NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(getApplicationContext()); notificationManagerCompat.notify(MainActivity.NOTIFICATION_ID, notification); } }