Help integrating Voice Recognizer Intent

Put your problem here if it does not fit any of the other categories.

Help integrating Voice Recognizer Intent

Postby neo187 » Tue Sep 13, 2011 2:24 pm

Hi all

I am trying to integrate the Voice Recognizer in my graphic app. I have a button and when pressed I'd like the intent to start and pass the result string to a string on the game.

I am following the Sample application on the android developers site: ... ition.html

So basically I have trimmed that so as to remove the layout and the buttons code since the game will be the default launch activity.

I have created a class inside my activity:

Code: Select all
       class VoiceRecognition extends Activity{
      private static final int VOICE_RECOGNITION_REQUEST_CODE = 1234;
      public void onCreate(Bundle savedInstanceState) {



           // 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) {
               spoken = "ok!";
           } else {
               spoken = "Recognizer not present";
      private void startVoiceRecognitionActivity() {
           Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
           intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo");
           startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);

        * Handle the results from the recognition activity.
       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(
               //mList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, matches));
               String listString = "";

               for (String s : matches)
                   listString += s + "\t";
               spoken = listString;

           super.onActivityResult(requestCode, resultCode, data);

Where "spoken" is a public string in the Game class. And then I have this code to launch it when a button is pressed:
Code: Select all
Intent dialogIntent = new Intent(getBaseContext(), VoiceRecognition.class);

But the app crashes with a Force Close screen when I try to press that button....

I am really new to Android development... Am I on the right track for this? The main app is using the OpenGL GLSurfaceView to draw the screen, not sure if that could be the issue with launching the recognizer window...

Any suggestions would be greatly appreciated!
Junior Developer
Junior Developer
Posts: 10
Joined: Wed Aug 31, 2011 9:44 am


Re: Help integrating Voice Recognizer Intent

Postby neo187 » Tue Sep 13, 2011 3:38 pm

The error in the LogCat says:
ActivityNotFoundException: Unable to find explicit activity class {..........GameScreen$VoiceRecognition} and it asks me if I am sure that I have declared it in the manifest which then I did this way <activity android:name=".GameScreen$VoiceRecognition"/> but still no luck!
Junior Developer
Junior Developer
Posts: 10
Joined: Wed Aug 31, 2011 9:44 am


Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 2 guests