我正在尝试使用Android Wear进行开发。我尝试了文档中提供的所有教程,但现在我想尝试做一些更聪明的事情。我正在尝试取回用户说的文本(使用计算机键盘编写的模拟器),所以我使用以下代码完成了它:
protected void voiceNotification() {
// Crete intent for the response action
Intent replyIntent = new Intent(this, ReplyActivity.class);
// Adding intent to pending intent
PendingIntent replyPendingIntent = PendingIntent.getActivity(this, 0,
replyIntent, 0);
// Build the notification
NotificationCompat.Builder replyNotificationBuilder = new NotificationCompat.Builder(
this);
replyNotificationBuilder
.setSmallIcon(android.R.drawable.ic_btn_speak_now);
replyNotificationBuilder.setContentTitle("Messaggio");
replyNotificationBuilder.setContentText("Testo del messaggio");
replyNotificationBuilder.setContentIntent(replyPendingIntent);
replyNotificationBuilder.setNumber(++numMessages);
replyNotificationBuilder.setAutoCancel(true);
replyNotificationBuilder.setSound(RingtoneManager
.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
replyNotificationBuilder.setVibrate(new long[] { 1000, 1000 });
replyNotificationBuilder.setTicker("Hai una nuova notifica!");
// Create remote input
RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY)
.setLabel(getResources().getString(R.string.reply_label))
.build();
// Create the wearable notification
Notification replyNotification = new WearableNotifications.Builder(replyNotificationBuilder)
.addRemoteInputForContentIntent(remoteInput)
.build();
// Get the instance of NotificationManagerCompat and send my notification
NotificationManagerCompat.from(this).notify(0, replyNotification);
}
使用模拟器上的这段代码,我得到了 2 个视图:一个是我的通知文本,另一个是我可以用语音回答通知(带模拟器的键盘)。它工作得很好,但我想知道是否有可能让我说的文本(用模拟器编写)在我的应用程序中做某事(我在模拟器显示屏上看到,在我说/写了一些东西之后,它出现了 2 个按钮“编辑”和“发送”,所以我认为使用“发送”按钮我可以在我的应用程序中获取文本来做某事)。我试图在文档中找出一些东西,但我什么也没找到。我希望你能帮助我得到这个文本。