Send an Intent with request on speech Recognizer - Android Intent

Android examples for Intent:Take Sound

Description

Send an Intent with request on speech Recognizer

Demo Code


import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.speech.RecognizerIntent;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;

public class Main{
    private static Activity ownerActivity;
    //from  ww w  .j  a  v a2s .  c  o m
    private static void startRecognitionActivity(Activity callerActivity) {

        // creating an Intent with ?RecognizerIntent.ACTION_RECOGNIZE_SPEECH?? action
        Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);

        // giving additional parameters:
        intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "What's up buddy?"); // user hint
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH); // setting recognition model, optimized for short phrases ? search queries
        intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1); // quantity of results we want to receive
        //choosing only 1st -  the most relevant

        // start Activity ant waiting the result
        ownerActivity.startActivityForResult(intent,
                SystemData.VOICE_RECOGNITION_REQUEST_CODE);
    }
}

Related Tutorials