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 8320641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:43:27+00:00 2026-06-08T22:43:27+00:00

There are many tutorials online for adding voice recognition to an android app. They

  • 0

There are many tutorials online for adding voice recognition to an android app. They are often confusing and the publishers of the coding are never available for questions. I need a basic overview of how to add voice recognition to my app (as an answer, not a link).

  • 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-08T22:43:29+00:00Added an answer on June 8, 2026 at 10:43 pm

    If you want to add voice recognition to your group’s Android app it is very simple.

    Throughout this tutorial you will need to add imports as you paste in the code.

    1. Create an xml file or use an existing one and make sure that you add a button and a listview.
    2. In a java class you need to extend activity and implement OnClickListener
      You will get an error that says you have unimplemented methods. Hover over it and add the unimplemented methods. We will add to this later.
    3. Next set up the button and listview in your java.

      public ListView mList;
      public Button speakButton;
      

      also add:

      public static final int VOICE_RECOGNITION_REQUEST_CODE = 1234;
      
    4. Next, make an OnCreate Method and set up the button and listener.

      speakButton = (Button) findViewById(R.id.btn_speak);
      speakButton.setOnClickListener(this);
      

      also add this method(we will set it up next)

      voiceinputbuttons();
      

      Remember to setContentView for the xml you are showing.

    5. Outside of your oncreate make a new method that looks like this.

      public void voiceinputbuttons() {
          speakButton = (Button) findViewById(R.id.btn_speak);
          mList = (ListView) findViewById(R.id.list);
      }
      
    6. Now you will have to set up your voice recognition activity by using the following code.

      public void startVoiceRecognitionActivity() {
          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 recognition demo");
          startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
      }
      
    7. Next, inside your onclick method from step 2 add the activity from step 6.

      startVoiceRecognitionActivity();
      
    8. Next we will have to set up another method. Copy and paste the following code.

      @Override
      public void onActivityResult(int requestCode, int resultCode, Intent data) {
          if (requestCode == VOICE_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK) {
              ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
              mList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, matches));
      

      matches is the result of voice input. It is a list of what the user possibly said. Using an if statement for the keyword you want to use allows the use of any activity if keywords match it is possible to set up multiple keywords to use the same activity so more than one word will allow the user To use the activity (makes it so the user doesn’t have to memorize words from a list) To use an activity from the voice input information simply use the following format;

      if (matches.contains("information")) {
          informationMenu();
      }
      

      NOTE: you can format the code any time by pressing ctrl+shift+F in eclipse.

    9. Now we are going to set up our method used by the code in step 8. This code creates an intent to direct the user to a new menu. You will need another xml and java class for this. Also, remember to add an activity to your manifest.

      public void informationMenu() {
          startActivity(new Intent("android.intent.action.INFOSCREEN"));
      }
      
    10. Finally you need to set up some code that will let the user know if the mic is operational. Paste this code inside of the OnCreate method at the end.

      // Check to see if a recognition activity is present
      // if running on AVD virtual device it will give this message. The mic
      // required only works on an actual android device
      PackageManager pm = getPackageManager();
      List activities = pm.queryIntentActivities(new Intent(
      RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
      if (activities.size() != 0) {
          voiceButton.setOnClickListener(this);
      } else {
          voiceButton.setEnabled(false);
          voiceButton.setText("Recognizer not present");
      }
      

    FINAL NOTE: Voice Recognition will not work on a virtual emulator because they can’t access the mic on your computer. The voice recognition will only work with an internet connection.

    This is approx. what your final code should look like in your java.

    package com.example.com.tutorialthread;
    
    import java.util.ArrayList;
    
    import android.os.Bundle;
    import android.app.Activity;
    import android.content.Intent;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.ArrayAdapter;
    import android.widget.Button;
    import android.widget.ListView;
    import android.speech.RecognizerIntent;
    import android.support.v4.app.NavUtils;
    
    public class main extends Activity implements OnClickListener {
    
    public ListView mList;
    public Button speakButton;
    
    public static final int VOICE_RECOGNITION_REQUEST_CODE = 1234;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
        speakButton = (Button) findViewById(R.id.btn_speak);
        speakButton.setOnClickListener(this);
    
        voiceinputbuttons();
    }
    
    public void informationMenu() {
        startActivity(new Intent("android.intent.action.INFOSCREEN"));
    }
    
    public void voiceinputbuttons() {
        speakButton = (Button) findViewById(R.id.btn_speak);
        mList = (ListView) findViewById(R.id.list);
    }
    
    public void startVoiceRecognitionActivity() {
        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 recognition demo");
        startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
    }
    
    public void onClick(View v) {
        // TODO Auto-generated method stub
        startVoiceRecognitionActivity();
    }
    
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, 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 matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
            mList.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, matches));
            // matches is the result of voice input. It is a list of what the
            // user possibly said.
            // Using an if statement for the keyword you want to use allows the
            // use of any activity if keywords match
            // it is possible to set up multiple keywords to use the same
            // activity so more than one word will allow the user
            // to use the activity (makes it so the user doesn't have to
            // memorize words from a list)
            // to use an activity from the voice input information simply use
            // the following format;
            // if (matches.contains("keyword here") { startActivity(new
            // Intent("name.of.manifest.ACTIVITY")
    
            if (matches.contains("information")) {
                informationMenu();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know there are many tutorials out there for getting started in C. However
I know there are many tutorials to use Dropbox as a Git repository, but
There are too many tutorials out there on monads that say... Look! here is
There are many similar questions, however they don't answer the problem of a url
I've seen many tutorials online that says you need to check $_SERVER['HTTPS'] if the
While attempting to build a website, i have gone through many online tutorials. Thanks
There are many tutorials that show you how to create the model instructions for
I see there are many tutorials about nhibernate but I cannot find a descent
There are many tutorials that show you how to create an active tab effect
There are many tutorials that talk about deleting index.php from the url. But I

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.