1

我正在尝试使用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 个按钮“编辑”和“发送”,所以我认为使用“发送”按钮我可以在我的应用程序中获取文本来做某事)。我试图在文档中找出一些东西,但我什么也没找到。我希望你能帮助我得到这个文本。

4

1 回答 1

2

您需要实现一个广播接收器来监听您定义的 pendingIntent - 来自用户的回复将通过您在 RemoteInput 中定义的额外字符串传递 - 在您的情况下,这将是EXTRA_VOICE_REPLY.

你可能想看看有人在 GitHub 上发布的这两个文件,以了解发生了什么。

http://git.io/emKcrw

http://git.io/_PRW_w

于 2014-03-26T16:04:10.457 回答