I start the Voice recognition activity in a non activity class (by passing in the activity) here is the code:
private static void startVoiceRecognitionActivity() {
// TODO Auto-generated method stub
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
"Talk");
myActivity.startActivityForResult(intent, REQUEST_CODE);
}
last line myActivity
is the activity i passed in to the class which has this method in.
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
for (final EditText editText : editTextHandlingList) {
if (requestCode == REQUEST_CODE && resultCode == theActivity.RESULT_OK) {
ArrayList<String> results = data
.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
//log the result }
}
}
Now the problem is onActivityResult
method. I want to be able to get the result back inside the same class and not in the activity.
If it is vague please ask me questions..
As I pass the activity to this class is there any way that i can do this? There should be some way to handle this outside.. If you have any questions please ask me.