diff options
author | Paul Rashidi <paulrashidi@google.com> | 2016-03-08 05:58:44 -0800 |
---|---|---|
committer | Paul Rashidi <paulrashidi@google.com> | 2016-03-08 13:37:40 -0800 |
commit | 0167af379a99b0951154f6b8abd0b5d92b5c3cd8 (patch) | |
tree | 1b64c8b573207111e635648e1418bd2f614deea0 /notification | |
parent | f0087bb0c1238d999a4ff70ccb4d94a30847378b (diff) | |
download | android-0167af379a99b0951154f6b8abd0b5d92b5c3cd8.tar.gz |
Updating sample to use RemoteInput compatible with non-car devices.
Change-Id: I5252cda89efaf43eca7d9aaddbfd41515df27445
Diffstat (limited to 'notification')
4 files changed, 35 insertions, 18 deletions
diff --git a/notification/MessagingService/Application/src/main/java/com/example/android/messagingservice/MessageReplyReceiver.java b/notification/MessagingService/Application/src/main/java/com/example/android/messagingservice/MessageReplyReceiver.java index 0a3eba69..44a2ee5f 100644 --- a/notification/MessagingService/Application/src/main/java/com/example/android/messagingservice/MessageReplyReceiver.java +++ b/notification/MessagingService/Application/src/main/java/com/example/android/messagingservice/MessageReplyReceiver.java @@ -21,10 +21,12 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.RemoteInput; +import android.support.v4.text.TextUtilsCompat; +import android.text.TextUtils; import android.util.Log; /** - * A receiver that gets called when a reply is sent to a given conversationId + * A receiver that gets called when a reply is sent to a given conversationId. */ public class MessageReplyReceiver extends BroadcastReceiver { @@ -51,7 +53,8 @@ public class MessageReplyReceiver extends BroadcastReceiver { private CharSequence getMessageText(Intent intent) { Bundle remoteInput = RemoteInput.getResultsFromIntent(intent); if (remoteInput != null) { - return remoteInput.getCharSequence(MessagingService.EXTRA_VOICE_REPLY); + return remoteInput.getCharSequence( + MessagingService.EXTRA_REMOTE_REPLY); } return null; } diff --git a/notification/MessagingService/Application/src/main/java/com/example/android/messagingservice/MessagingService.java b/notification/MessagingService/Application/src/main/java/com/example/android/messagingservice/MessagingService.java index 73199ed5..37a05f6a 100644 --- a/notification/MessagingService/Application/src/main/java/com/example/android/messagingservice/MessagingService.java +++ b/notification/MessagingService/Application/src/main/java/com/example/android/messagingservice/MessagingService.java @@ -39,11 +39,10 @@ public class MessagingService extends Service { private static final String EOL = "\n"; private static final String READ_ACTION = "com.example.android.messagingservice.ACTION_MESSAGE_READ"; - public static final String REPLY_ACTION = "com.example.android.messagingservice.ACTION_MESSAGE_REPLY"; public static final String CONVERSATION_ID = "conversation_id"; - public static final String EXTRA_VOICE_REPLY = "extra_voice_reply"; + public static final String EXTRA_REMOTE_REPLY = "extra_remote_reply"; public static final int MSG_SEND_NOTIFICATION = 1; private NotificationManagerCompat mNotificationManager; @@ -93,9 +92,10 @@ public class MessagingService extends Service { getMessageReadIntent(conversation.getConversationId()), PendingIntent.FLAG_UPDATE_CURRENT); - // Build a RemoteInput for receiving voice input in a Car Notification - RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY) - .setLabel(getApplicationContext().getString(R.string.notification_reply)) + // Build a RemoteInput for receiving voice input in a Car Notification or text input on + // devices that support text input (like devices on Android N and above). + RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_REMOTE_REPLY) + .setLabel(getString(R.string.reply)) .build(); // Building a Pending Intent for the reply action to trigger @@ -104,6 +104,11 @@ public class MessagingService extends Service { getMessageReplyIntent(conversation.getConversationId()), PendingIntent.FLAG_UPDATE_CURRENT); + // Build an Android N compatible Remote Input enabled action. + NotificationCompat.Action actionReplyByRemoteInput = new NotificationCompat.Action.Builder( + R.drawable.abc_btn_check_material, getString(R.string.reply), replyIntent) + .addRemoteInput(remoteInput).build(); + // Create the UnreadConversation and populate it with the participant name, // read and reply intents. UnreadConversation.Builder unreadConvBuilder = @@ -134,8 +139,8 @@ public class MessagingService extends Service { .setContentIntent(readPendingIntent) .extend(new CarExtender() .setUnreadConversation(unreadConvBuilder.build()) - .setColor(getApplicationContext() - .getResources().getColor(R.color.default_color_light))); + .setColor(getApplicationContext().getColor(R.color.default_color_light))) + .addAction(actionReplyByRemoteInput); MessageLogger.logMessage(getApplicationContext(), "Sending notification " + conversation.getConversationId() + " conversation: " + conversation); diff --git a/notification/MessagingService/Application/src/main/res/values/strings.xml b/notification/MessagingService/Application/src/main/res/values/strings.xml index 3f8390df..4527de56 100644 --- a/notification/MessagingService/Application/src/main/res/values/strings.xml +++ b/notification/MessagingService/Application/src/main/res/values/strings.xml @@ -16,7 +16,7 @@ --> <resources> <string name="app_name">Messaging Sample</string> - <string name="notification_reply">Reply by Voice</string> + <string name="reply">Reply</string> <string name="send_2_conversations">Send 2 conversations with 1 message</string> <string name="send_1_conversation">Send 1 conversation with 1 message</string> <string name="send_1_conv_3_messages">Send 1 conversation with 3 messages</string> diff --git a/notification/MessagingService/template-params.xml b/notification/MessagingService/template-params.xml index 9a68d742..c3aef393 100644 --- a/notification/MessagingService/template-params.xml +++ b/notification/MessagingService/template-params.xml @@ -16,7 +16,7 @@ --> <sample> <name>MessagingService</name> - <group>Notification</group> + <group>Android N Preview</group> <package>com.example.android.messagingservice</package> <minSdk>21</minSdk> @@ -25,9 +25,13 @@ <intro> <![CDATA[ This sample shows a simple service that sends notifications using -NotificationCompat. In addition to sending a notification, it also extends -the notification with a CarExtender to make it compatible with Android Auto. -Each unread conversation from a user is sent as a distinct notification. +NotificationCompat. It also extends the notification with Remote +Input to allow Android N devices to reply via text directly from +the notification without having to open an app. The same Remote +Input usage also allows Android Auto users to respond by voice +when the notifications is presented in that experience. +Note: Each unread conversation from a user is sent as a distinct +notification. ]]> </intro> </strings> @@ -36,7 +40,8 @@ Each unread conversation from a user is sent as a distinct notification. <template src="base-application" /> <metadata> <status>PUBLISHED</status> - <categories>UI, Notification</categories> + <categories>Android N Preview</categories> + <!-- Old Categories: UI, Notification --> <technologies>Android</technologies> <languages>Java</languages> <solutions>Mobile</solutions> @@ -56,9 +61,13 @@ Each unread conversation from a user is sent as a distinct notification. <description> <![CDATA[ This sample shows a simple service that sends notifications using -NotificationCompat. In addition to sending a notification, it also extends -the notification with a CarExtender to make it compatible with Android Auto. -Each unread conversation from a user is sent as a distinct notification. +NotificationCompat. It also extends the notification with Remote +Input to allow Android N devices to reply via text directly from +the notification without having to open an App. The same Remote +Input object also allows Android Auto users to respond by voice +when the notification is presented there. +Note: Each unread conversation from a user is sent as a distinct +notification. ]]></description> <intro> <![CDATA[ |