2

에서 영구 notification 일종의 텍스트, 그리고 내 목표는 같다이구글의 음성은 내가 만든 알림

1) 사용자는 notification
2) Google Speech to Text activity 시작에 도청 및 음성 입력을 받아
3) 입력이 텍스트로 변환되고 새 활동이 시작되어 텍스트가 표시됩니다.

는 여기에 지금 far-- 시도했습니다 무엇

지금은 내가 일반적으로 startActivityForResult(resultIntent, REQ_CODE_SPEECH_INPUT);를 사용하여 내 activity에서 그것을 처리하여 인식기 Intent의 결과를 처리 할 수 ​​있다는 것을 알고

NotificationCompat.Builder builder = new NotificationCompat.Builder(MainActivity.this) 
      .setSmallIcon(android.R.drawable.ic_dialog_alert) 
      .setContentTitle("Tap for voice input") 
      .setContentText("Hi"); 

    Intent resultIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); 
    resultIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, 
      RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); 
    resultIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault()); 
    resultIntent.putExtra(RecognizerIntent.EXTRA_PROMPT, 
      getString(R.string.speech_prompt)); 
    PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); 
    builder.setContentIntent(pendingIntent); 

    Notification notification = builder.build(); 
    notification.flags = Notification.FLAG_NO_CLEAR; 

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(MainActivity.this); 
    notificationManager.notify(0, notification); 
.

그러나 notification의 경우 pendingIntent에 내 의도를 전달해야합니다.

나는 이것을 얻을 수있는 어떤 방법이라도?

편집 1 :

나는 새로운 활동을 시작하고 개방 음성 Google 음성 프롬프트하지만 추가 매개 변수와 같이 시작하기 전에 나는 나의 활동에 전달하기 위해 변환 된 문자열을 할 수 있습니다 의도 ...

+1

내가 제공 한 답변이 필요에 가장 적합하다고 생각합니다. 그렇지 않으면 더 많은 기술을 얻으려면 'SpeechRecognizer' 클래스를 사용하여 서비스에서 음성 입력을 가져온 다음 해당 매개 변수를 활동이 완료되면 활동. – brandall

답변

2

조정자로 "보이지 않는"Activity을 사용하십시오. UI가없는 활동을 가질 수 있습니다 (예 : this SO post, Emanuel Moecklin 참조). Activity 시작을 텍스트로 STT 변환

  • 구글 음성의 결과를 얻을 startActivityForResult()

    • 사용자가 UI없이
    • Activity이 시작 알림을 도청하고 통화 : 그래서 당신은 다음과 같이 앱 흐름을 수정할 수 있습니다 음성 입력을받습니다.
    • 입력이 텍스트로 변환되어 UI- less Activity
    • ...으로 보내집니다. 그러면 해당 텍스트를 나타내는 새 Activity이 시작됩니다.