我是android的新手,目前正在开发适用于Voice Command API的小应用程序.例如,如果我说蓝牙,它会将手机的蓝牙切换到开/关模式(反之亦然).
请帮我这样做....
感谢Anvance ......
key*_*fer 10
使用起来相当简单:
private void startVoiceRecognitionActivity() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
//uses free form text input
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
//Puts a customized message to the prompt
intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
getString(R.string.listenprompt));
startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
}
/**
* Handles 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);
//Turn on or off bluetooth here
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
Run Code Online (Sandbox Code Playgroud)
然后startVoiceRecognitionActivity()在您需要的任何地方调用代码中的from.当然,你需要有权利访问互联网
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
Run Code Online (Sandbox Code Playgroud)
在你的Android.manifest中.
| 归档时间: |
|
| 查看次数: |
11940 次 |
| 最近记录: |