SLAM/mobile/src/main/java/de/vanitasvitae/slam/receiver/MessageReplyReceiver.java

58 lines
2.1 KiB
Java

/*
* Copyright 2018 Paul Schaub
*
* This code is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package de.vanitasvitae.slam.receiver;
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;
import de.vanitasvitae.slam.service.MyMessagingService;
/**
* 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 (MyMessagingService.REPLY_ACTION.equals(intent.getAction())) {
int conversationId = intent.getIntExtra(MyMessagingService.CONVERSATION_ID, -1);
CharSequence reply = getMessageText(intent);
Log.d(TAG, "Got reply (" + reply + ") for ConversationId " + conversationId);
}
}
/**
* 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(MyMessagingService.EXTRA_VOICE_REPLY);
}
return null;
}
}