こんにちはアンドロイドデベロッパーANDROID.Googleポップアップを表示せずにテキストに音声入力する方法
私はアンドロイド開発の初心者です。この問題に固執しました -
私は音声入力をしたいですが、私はGoogleポップアップを表示したくありません。私は音声入力がない複数のアプリを見てきました。だから多分誰かがそれを理解するのを助けることができますか?
のスクリーンショットは、MainActivity
の私のコードですパブリッククラスMainActivityはAppCompatActivity {
private TextView resultTV;
/**
* ATTENTION: This was auto-generated to implement the App Indexing API.
* See https://g.co/AppIndexing/AndroidStudio for more information.
*/
private GoogleApiClient client;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
resultTV = (TextView) findViewById(R.id.resultTV);
}
public void onButtonClick(View view) {
if (view.getId() == R.id.imageButton) {
promtSpeechInput();
}
}
public void promtSpeechInput() {
Intent i = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
i.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
i.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
i.putExtra(RecognizerIntent.EXTRA_PROMPT, "SAY SOMETHING");
i.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true);
try {
startActivityForResult(i, 100);
Toast.makeText(MainActivity.this, "Say something kiddo", Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(MainActivity.this, "Sorry, your device not support speech inputs", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
public void onActivityResult(int request_code, int result_code, Intent i){
super.onActivityResult(request_code,result_code,i);
switch (request_code)
{
case 100: if(result_code == RESULT_OK && i != null){
ArrayList<String> result = i.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
resultTV.setText(result.get(0));
}
break;
}
ありがとうございます。まだ動作していない、あなたはアンドロイドのマニフェストパーミッションを共有していただけますか? :) –
@VaclovasRekašiusJr。私はちょうど編集して、今答えの必要な許可を追加しました,,,あなたはそれを確認することができます – user5894647
@VaclovasRekašiusJr。そして、私の仕事が – user5894647