2014-03-26 107 views
1

我正在尝试使用Android Wear进行开发。我尝试了文档中提供的所有教程,但现在我想尝试做更聪明的事情。我试图找回那种用户表示(与电脑键盘写仿真器)的文本,所以我这个代码所做的那样: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按钮“编辑“和”发送“,所以我认为使用按钮”发送“我可以在我的应用程序中的文本做一些事情)。我试图找出文件中的某些内容,但我什么也没找到。我希望你能帮助我得到这个文本。

回答

2

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

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

http://git.io/emKcrw

http://git.io/_PRW_w

+0

这看起来太好了,谢谢,我会努力学习,并在我的演示应用程序实现:) – lucgian841