プログラムで[今すぐ話す]ダイアログを開くことはできますか?
現在、ユーザーが[検索]ボタンをタップすると、ダイアログが開き、ソフトキーボードが自動的に開くので、ユーザーはテキストエディットフィールドをタップする必要がありません。
ダイアログを開き、[今すぐ話す]ウィンドウを自動的に開く代替の[音声で検索]を提供したいと思います。したがって、ユーザーはキーボードの「マイク」ボタンを見つけてタップする必要はありません。
何か案は?
プログラムで[今すぐ話す]ダイアログを開くことはできますか?
現在、ユーザーが[検索]ボタンをタップすると、ダイアログが開き、ソフトキーボードが自動的に開くので、ユーザーはテキストエディットフィールドをタップする必要がありません。
ダイアログを開き、[今すぐ話す]ウィンドウを自動的に開く代替の[音声で検索]を提供したいと思います。したがって、ユーザーはキーボードの「マイク」ボタンを見つけてタップする必要はありません。
何か案は?
はい、可能です。AndroidSDKのApiDemos
サンプルをご覧ください。という名前のアクティビティがありVoiceRecognition
、それを利用しRecognizerIntent
ます。
基本的に、あなたがする必要があるのは、いくつかの追加機能で適切な意図を作成し、結果を読むことだけです。
private static final int VOICE_RECOGNITION_REQUEST_CODE = 1234;
private void startVoiceRecognitionActivity() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
// identifying your application to the Google service
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getClass().getPackage().getName());
// hint in the dialog
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo");
// hint to the recognizer about what the user is going to say
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
// number of results
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 5);
// recognition language
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE,"en-US");
startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == VOICE_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK) {
ArrayList<String> matches = data.getStringArrayListExtra(
RecognizerIntent.EXTRA_RESULTS);
// do whatever you want with the results
}
super.onActivityResult(requestCode, resultCode, data);
}