Merge branch 'readonly-p4-donut' into donut
This commit is contained in:
committed by
The Android Open Source Project
commit
cda0fbd1df
@@ -20,6 +20,8 @@ import com.example.android.apis.R;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.os.Bundle;
|
||||
import android.speech.RecognizerIntent;
|
||||
import android.view.View;
|
||||
@@ -29,6 +31,7 @@ import android.widget.Button;
|
||||
import android.widget.ListView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Sample code that invokes the speech recognition intent API.
|
||||
@@ -54,8 +57,16 @@ public class VoiceRecognition extends Activity implements OnClickListener {
|
||||
|
||||
mList = (ListView) findViewById(R.id.list);
|
||||
|
||||
// Attach actions to buttons
|
||||
// Check to see if a recognition activity is present
|
||||
PackageManager pm = getPackageManager();
|
||||
List<ResolveInfo> activities = pm.queryIntentActivities(
|
||||
new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
|
||||
if (activities.size() != 0) {
|
||||
speakButton.setOnClickListener(this);
|
||||
} else {
|
||||
speakButton.setEnabled(false);
|
||||
speakButton.setText("Recognizer not present");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,7 +82,6 @@ public class VoiceRecognition extends Activity implements OnClickListener {
|
||||
* Fire an intent to start the speech recognition activity.
|
||||
*/
|
||||
private void startVoiceRecognitionActivity() {
|
||||
//TODO Get these values from constants
|
||||
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
|
||||
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
|
||||
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
|
||||
@@ -85,6 +95,7 @@ public class VoiceRecognition extends Activity implements OnClickListener {
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode == VOICE_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK) {
|
||||
// Fill the list view with the strings the recognizer thought it could have heard
|
||||
ArrayList<String> matches = data.getStringArrayListExtra(
|
||||
RecognizerIntent.EXTRA_RESULTS);
|
||||
mList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
|
||||
|
||||
Reference in New Issue
Block a user