summaryrefslogtreecommitdiffstats
path: root/samples
diff options
context:
space:
mode:
authorJeff Hamilton <>2009-04-21 15:09:35 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2009-04-21 15:09:35 -0700
commit136d537b791224923e29d46679cbf9dc0783ecec (patch)
treecc056f8d6c83efdd821a27a7ef01728636fbc0ca /samples
parentee8f65c4f76965873842ecc25e40a3ca6774d40c (diff)
downloadandroid_development-136d537b791224923e29d46679cbf9dc0783ecec.tar.gz
android_development-136d537b791224923e29d46679cbf9dc0783ecec.tar.bz2
android_development-136d537b791224923e29d46679cbf9dc0783ecec.zip
AI 147247: am: CL 147243 Make the API sample check to see if there is anything installed to handle the recognition intent.
Original author: jham Merged from: //branches/cupcake/... Automated import of CL 147247
Diffstat (limited to 'samples')
-rw-r--r--samples/ApiDemos/src/com/example/android/apis/app/VoiceRecognition.java17
1 files changed, 14 insertions, 3 deletions
diff --git a/samples/ApiDemos/src/com/example/android/apis/app/VoiceRecognition.java b/samples/ApiDemos/src/com/example/android/apis/app/VoiceRecognition.java
index 1a4b5e4a0..3094afe0a 100644
--- a/samples/ApiDemos/src/com/example/android/apis/app/VoiceRecognition.java
+++ b/samples/ApiDemos/src/com/example/android/apis/app/VoiceRecognition.java
@@ -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
- speakButton.setOnClickListener(this);
+ // 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,