summaryrefslogtreecommitdiff
path: root/AutoMessagingDemo/app/src/main/java/com/example/android/automessagingdemo/MessageReplyReceiver.java
diff options
context:
space:
mode:
authorNagesh Susarla <nageshs@google.com>2014-09-18 16:40:29 -0700
committerNagesh Susarla <nageshs@google.com>2014-10-22 16:30:29 -0700
commitcb0b5ab8affad7af3fccb68a13197a7b0e3993b1 (patch)
tree48f783afd962539bb1425351fdbfd5432bba4b9b /AutoMessagingDemo/app/src/main/java/com/example/android/automessagingdemo/MessageReplyReceiver.java
parent7c700e80b902c8f7778ffd63c287ac5710fd69ef (diff)
downloaddemos-cb0b5ab8affad7af3fccb68a13197a7b0e3993b1.tar.gz
Auto Messaging API Sample First draft
Create a simple application that lets developers send a few variations of notifications such as 1. A conversation with single message 2. Multiple conversations with either single or multiple messages. The Notifications are extended with the CarExtender class and thus can be seen either on the emulator or GearHead dash 3. Add README.txt 4. Update the sample to use the latest android-auto-sdk.jar 5. refactor code to only expose the features in the sdk (no multiple partipants) Bug: 17582488 Change-Id: Ic5d385361dca5e74c8b5e96dbc11fe11cdb421f7
Diffstat (limited to 'AutoMessagingDemo/app/src/main/java/com/example/android/automessagingdemo/MessageReplyReceiver.java')
-rw-r--r--AutoMessagingDemo/app/src/main/java/com/example/android/automessagingdemo/MessageReplyReceiver.java58
1 files changed, 58 insertions, 0 deletions
diff --git a/AutoMessagingDemo/app/src/main/java/com/example/android/automessagingdemo/MessageReplyReceiver.java b/AutoMessagingDemo/app/src/main/java/com/example/android/automessagingdemo/MessageReplyReceiver.java
new file mode 100644
index 0000000..c9087d2
--- /dev/null
+++ b/AutoMessagingDemo/app/src/main/java/com/example/android/automessagingdemo/MessageReplyReceiver.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.automessagingdemo;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.support.v4.app.RemoteInput;
+import android.util.Log;
+
+/**
+ * A receiver that gets called when a reply is sent to a given conversationId
+ */
+public class MessageReplyReceiver extends BroadcastReceiver {
+
+ private static final String TAG = MessageReplyReceiver.class.getSimpleName();
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (MessagingService.REPLY_ACTION.equals(intent.getAction())) {
+ int conversationId = intent.getIntExtra(MessagingService.CONVERSATION_ID, -1);
+ CharSequence reply = getMessageText(intent);
+ if (conversationId != -1) {
+ Log.d(TAG, "Got reply (" + reply + ") for ConversationId " + conversationId);
+ MessageLogger.logMessage(context, "ConversationId: " + conversationId +
+ " received a reply: [" + reply + "]");
+ }
+ }
+ }
+
+ /**
+ * Get the message text from the intent.
+ * Note that you should call {@code RemoteInput#getResultsFromIntent(intent)} to process
+ * the RemoteInput.
+ */
+ private CharSequence getMessageText(Intent intent) {
+ Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
+ if (remoteInput != null) {
+ return remoteInput.getCharSequence(MessagingService.EXTRA_VOICE_REPLY);
+ }
+ return null;
+ }
+}