2014-03-26 179 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