Voice Input
Android Wear device using touch screen and voice to input command. You can use intent remote input to dictation voice command.
Pending Intent
Intent intent = new Intent(this,NotificationActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_UPDATE_CURRENT);
String replayLabel = getResources().getString(R.string.label_reply);
String[] replyChoices = getResources().getStringArray(R.array.reply_choices);
Voice Input with choices
RemoteInput remoteInput = new RemoteInput.Builder(NotificationUtils.EXTRA_VOICE_REPLY)
.setLabel(replayLabel)
.setChoices(replyChoices)
.build();
Set Action Menu
NotificationCompat.Action action = new NotificationCompat.Action.Builder(R.drawable.ic_reply,"Answer",pendingIntent)
.addRemoteInput(remoteInput)
.build();
Set Notification
Notification notification = new NotificationCompat.Builder(this)
.setContentTitle("Notification Title")
.setContentText("Notification Text")
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(pendingIntent)
.extend(new NotificationCompat.WearableExtender().addAction(action))
.build();
Show Notification
NotificationManagerCompat manager = NotificationManagerCompat.from(this);
manager.notify(1,notification);
Remote Input Result
private CharSequence getMessageText(Intent intent) {
Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
if (remoteInput!=null) {
return remoteInput.getCharSequence(NotificationUtils.EXTRA_VOICE_REPLY);
}
return null;
}
Remote Input Result
private CharSequence getMessageText(Intent intent) {
Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
if (remoteInput!=null) {
return remoteInput.getCharSequence(NotificationUtils.EXTRA_VOICE_REPLY);
}
return null;
}
Thank You
Licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.