我正在尝试在我的应用中实现语音识别。它可以很好地加载语音识别面板,识别你说的内容,然后一旦完成它就应该返回到调用onActivityResult方法的应用程序。不幸的是它没有,只是返回到设备主屏幕。我有什么想法吗?
static final int VOICE_RECOGNITION_REQUEST_CODE = 1234;
/**
* Handler from the listening thread
*/
public Handler mhandle = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case MAXOVER_MSG :
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
break;
default :
super.handleMessage(msg);
break;
}
}
};
/**
* 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) {
Log.i("hmm","This never seems to get called..");
}
super.onActivityResult(requestCode, resultCode, data);
}
答案 0 :(得分:0)
您的申请可能由于某种原因finish
。您是SINGLE_TOP或SINGLE_TASK还是其他一些特殊功能标志来启动您的Activity(在启动它的Intent或AndroidManifest.xml中)?