In general, I did what I asked in the previous question.
public class VoiceActivity extends Activity implements OnClickListener { private TextView mText; private SpeechRecognizer sr; private static final String TAG = "MyActivity"; public String str; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button speakButton = (Button) findViewById(R.id.speakButton); mText = (TextView) findViewById(R.id.textView1); speakButton.setOnClickListener(this); sr = SpeechRecognizer.createSpeechRecognizer(this); sr.setRecognitionListener(new listener()); } class listener implements RecognitionListener { public void onReadyForSpeech(Bundle params) { Log.d(TAG, "onReadyForSpeech"); } public void onBeginningOfSpeech() { Log.d(TAG, "onBeginningOfSpeech"); } public void onRmsChanged(float rmsdB) { Log.d(TAG, "onRmsChanged"); } public void onBufferReceived(byte[] buffer) { Log.d(TAG, "onBufferReceived"); } public void onEndOfSpeech() { Log.d(TAG, "onEndofSpeech"); } public void onError(int error) { Log.d(TAG, "error " + error); mText.setText("error " + error); } public void onResults(Bundle results) { str = new String(); Log.d(TAG, "onResults " + results); ArrayList<String> data = results .getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION); for (int i = 0; i < data.size(); i++) { Log.d(TAG, "result " + data.get(i)); str += data.get(i); } mText.setText("results: " + str); } public void onPartialResults(Bundle partialResults) { Log.d(TAG, "onPartialResults"); } public void onEvent(int eventType, Bundle params) { Log.d(TAG, "onEvent " + eventType); } } public void onClick(View v) { if (v.getId() == R.id.speakButton) { Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, "com.moc"); intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1); sr.startListening(intent); } } } I am interested in the following question: how to correctly forward the received string to another Activity, without outputting it to TextViev?
Update: But how to make an automatic transition to another activity after determining the voice (click - say - opens the next. Activation and the result in it)? Simply, if like in my example, he writes an error in the intent.setClass string (this, SecondActivity.class);
There was a thought:
public void onResults(Bundle results) { str = new String(); Log.d(TAG, "onResults " + results); ArrayList<String> data = results .getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION); for (int i = 0; i < data.size(); i++) { Log.d(TAG, "result " + data.get(i)); str += data.get(i); } Intent intent = new Intent(); Bundle b = new Bundle(); b.putString("StrID", str); intent.putExtras(b); intent.setClass(this, SecondActivity.class); startActivity(intent); } but it is extremely wrong.