Android Spracherkennung funktioniert nicht

Ich verwende dieses Beispiel von newboston und es fordert mich zur Aufnahme auf, aber nachdem es das Gesagte erkannt hat, wird die Listenansicht nicht aktualisiert.

Hier ist der Code.

public class MainActivity extends Activity {

private static final int RECOGNIZER_RESULT = 1234;
ListView list;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    list = (ListView) findViewById(R.id.list);

    Button btn_speach = (Button)findViewById(R.id.btn_speak);
    btn_speach.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
            intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
            intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech to search");
            startActivityForResult(intent, RECOGNIZER_RESULT);

        }
    });
}



@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if(requestCode == RECOGNIZER_RESULT && requestCode == RESULT_OK){
        ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
        list.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, matches));
        for(int i = 0; i < matches.size(); i++){
            Log.i("MainActivity", matches.get(i));
        }
    }

    super.onActivityResult(requestCode, resultCode, data);
}



@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}
}

Hier ist das XML-Layout.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <Button
        android:id="@+id/btn_speak"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:text="Button" />

    <ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/button1" >

    </ListView>

</RelativeLayout>

Ich bekomme keine Fehler. Und der folgende Code druckt auch in LogCat nichts.

for(int i = 0; i < matches.size(); i++){
            Log.i("MainActivity", matches.get(i));
}

Und ich teste auf meinem Android-Gerät mit Spracherkennungsfunktion.

Antworten auf die Frage(1)

Ihre Antwort auf die Frage