package tif.makeyourjarvis;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.app.SearchManager;
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;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.Toast;
public class MainActivity extends Activity {
//ListView mList = (ListView) findViewById(R.id.list);
private static final int VOICE_RECOGNITION_REQUEST_CODE = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
startVoiceRecognitionActivity();
}
private void startVoiceRecognitionActivity()
{
//语音识别的Action
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);
}
protected 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));
Toast.makeText(getApplicationContext(), matches.get(0),Toast.LENGTH_SHORT).show();
startVoiceRecognitionActivity() ;
}
super.onActivityResult(requestCode, resultCode, data);
}
}
沒有留言:
張貼留言