Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7921951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:46:48+00:00 2026-06-03T16:46:48+00:00

I am using the activity, voicerecognition.java , provided by Google to allow the user

  • 0

I am using the activity, voicerecognition.java, provided by Google to allow the user to choose a language, talk into the handset, and view what they have just said. It works when I take out all the language constants, but when I put the language options in, I get errors.
For example:

  • The method getVoiceDetailsIntent(VoiceRecognition) is undefined for the type
  • EXTRA_SUPPORTED_LANGUAGES cannot be resolved or is not a field
  • EXTRA_LANGUAGE_PREFERENCE cannot be resolved or is not a field
  • The method run() of type new Runnable(){} must override a superclass method

I thought I might just need to update the SDK or something but everything is up to date. I have no idea what is wrong since I copied the activity exactly as is on the link provided.

package com.sample.voicerecog;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.os.Handler;
import android.speech.RecognizerIntent;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.SpinnerAdapter;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;

public class VoiceRecognition extends Activity implements OnClickListener {    
private static final String TAG = "VoiceRecognition";    
private static final int VOICE_RECOGNITION_REQUEST_CODE = 1234;    
private ListView mList;    
private Handler mHandler;    
private Spinner mSupportedLanguageView;    

/**     
 * Called with the activity is first created.     
 */    
@Override    
public void onCreate(Bundle savedInstanceState) {        
    super.onCreate(savedInstanceState);        
    mHandler = new Handler();        

    // Inflate our UI from its XML layout description.        
    setContentView(R.layout.voice_recognition);        

    // Get display items for later interaction        
    Button speakButton = (Button) findViewById(R.id.btn_speak);        
    mList = (ListView) findViewById(R.id.list);        
    mSupportedLanguageView = (Spinner) findViewById(R.id.supported_languages);        
    // 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");   
    }      

    // Most of the applications do not have to handle the voice settings. If the application     
    // does not require a recognition in a specific language (i.e., different from the system     
    // locale), the application does not need to read the voice settings.      
    refreshVoiceSettings();  
}

/**
 * Handle the click on the start recognition button.     
 */    
public void onClick(View v) {        
    if (v.getId() == R.id.btn_speak) {           
        startVoiceRecognitionActivity();        
    }    
}   

/**     
 * Fire an intent to start the speech recognition activity.     
 */    
private void startVoiceRecognitionActivity() {       
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);        

    // Display an hint to the user about what he should say.      
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo");    

    // Given an hint to the recognizer about what the user is going to say       
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,              
            RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);    

    // Specify how many results you want to receive. The results will be sorted   
    // where the first result is the one with higher confidence.       
    intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 5); 

    // Specify the recognition language. This parameter has to be specified only if the     
    // recognition has to be done in a specific language and not the default one (i.e., the   
    // system locale). Most of the applications do not have to set this parameter.  
    if (!mSupportedLanguageView.getSelectedItem().toString().equals("Default")) {     
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE,                  
                mSupportedLanguageView.getSelectedItem().toString());  
    }    
    startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);   
}    

/**     
 * Handle the results from the recognition activity.     
 */    
@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,      
                matches));       
    } 
    super.onActivityResult(requestCode, resultCode, data);   
}

private void refreshVoiceSettings() {      
    Log.i(TAG, "Sending broadcast");    
    sendOrderedBroadcast(RecognizerIntent.getVoiceDetailsIntent(this), null,   
            new SupportedLanguageBroadcastReceiver(), null, Activity.RESULT_OK, null, null);   
} 

private void updateSupportedLanguages(List<String> languages) {    
    // We add "Default" at the beginning of the list to simulate default language.   
    languages.add(0, "Default");   

    SpinnerAdapter adapter = new ArrayAdapter<CharSequence>(this,    
            android.R.layout.simple_spinner_item, languages.toArray(    
                    new String[languages.size()])); 
    mSupportedLanguageView.setAdapter(adapter); 
}

private void updateLanguagePreference(String language) {      
    TextView textView = (TextView) findViewById(R.id.language_preference);     
    textView.setText(language); 
}  

/**     
 * Handles the response of the broadcast request about the recognizer supported languages.     
 *     
 * The receiver is required only if the application wants to do recognition in a specific language.     
 */  

private class SupportedLanguageBroadcastReceiver extends BroadcastReceiver {      
    @Override  
    public void onReceive(Context context, final Intent intent) {     
        Log.i(TAG, "Receiving broadcast " + intent);  
        final Bundle extra = getResultExtras(false); 
        if (getResultCode() != Activity.RESULT_OK) {    
            mHandler.post(new Runnable() {     
                @Override        
                public void run() {              
                    showToast("Error code:" + getResultCode());    
                }       
            });   
        }
        if (extra == null) {        
            mHandler.post(new Runnable() {          
                @Override             
                public void run() {  
                    showToast("No extra");       
                }
            });
        }      
        if (extra.containsKey(RecognizerIntent.EXTRA_SUPPORTED_LANGUAGES)) {         
            mHandler.post(new Runnable() {      
                @Override       
                public void run() {          
                    updateSupportedLanguages(extra.getStringArrayList(      
                            RecognizerIntent.EXTRA_SUPPORTED_LANGUAGES));     
                }
            });
        }      
        if (extra.containsKey(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE)) {    
            mHandler.post(new Runnable() {         
                @Override      
                public void run() {          
                    updateLanguagePreference(     
                            extra.getString(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE));       
                }
            });
        }
    }

    private void showToast(String text) {      
        Toast.makeText(VoiceRecognition.this, text, 1000).show();   
    }
}
}

Any help is appreciated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T16:46:51+00:00Added an answer on June 3, 2026 at 4:46 pm

    It appears that your project is at a lower API level than level 8. To fix this, if you are using Eclipse, right click on your project and click properties. Choose Android from the menu on the left, and select a different project build target. If you don’t find one at level 8 or higher, click on Window -> Android SDK Manager and install one. You can see what features of RecognizerIntent are available at the various API levels here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I always designed/developed/released a software or web project myself/independent activity using java/vb.net and php
I tried using the following code in .java(main activity): final ImageView diskView1 = (ImageView)
Hi I have an Activity(Activity_1) which calls another Activity(Activity_2) using activity for result. In
How can I limit the number of rows returned using activity.managedQuery()? I am pretty
I Have a Service and i interact with it from an activity using Binding.
I am using an InvokeProcess activity in TFS 2010 to try and run the
I tried to turn on the Activity Monitor using SQL Server 2008 Management Studio
I'm thinking about using a ViewFlipper for an Wizard like Activity. But I see
i am using a class which extends Handler class to update my activity UI.
I am using the following code to open a new Activity from my current

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.