-2

In my google voice recognition, I'm trying to add commands. The commands should be in this piece of code:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
        // add commands 
    }
}

I am guessing it would be a else if statement but I'm confused on how to start it.

if() {
    // put code here
}

But what should I put in the if and the put code here?

Tunaki
  • 132,869
  • 46
  • 340
  • 423
yup
  • 1

1 Answers1

0

You should check the requestCode and resultCode like this:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == SystemData.VOICE_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK) {
        ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
        // TODO something with matches
    }
    super.onActivityResult(requestCode, resultCode, data);
}

The 'matches' ArrayList will contain all the recognized words in order.

ehehhh
  • 1,066
  • 3
  • 16
  • 27
  • So should i create an array called 'matches' with the keywords in it? Where should i put this array. Then after i have the array, how should i do the code in the onActivityResult? – yup Nov 20 '15 at 22:27
  • The arraylist called matches will get "created" for you, all you need to do is iterate through it and apply some logic on each item (where the TODO is). – ehehhh Nov 21 '15 at 07:19