如何从服务中启动ACTION_VOICE_COMMAND Intent?

时间:2012-03-07 21:27:58

标签: java android android-activity android-intent

我有以下代码在我的服务中启动Intent:

Intent voiceCommandIntent = new Intent(Intent.ACTION_VOICE_COMMAND);
            voiceCommandIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            appContext.startActivity(voiceCommandIntent);

我收到错误

No Activity Found to Handle Intent

这是stacktrace:

03-07 20:12:56.796: W/System.err(18401): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VOICE_COMMAND flg=0x10000000 }
03-07 20:12:56.796: I/ActivityManager(1120): Starting activity: Intent { act=android.intent.action.VOICE_COMMAND flg=0x10000000 }
03-07 20:12:56.802: W/System.err(18401):    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1408)
03-07 20:12:56.802: W/System.err(18401):    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
03-07 20:12:56.802: W/System.err(18401):    at android.app.ContextImpl.startActivity(ContextImpl.java:649)
03-07 20:12:56.802: W/System.err(18401):    at android.content.ContextWrapper.startActivity(ContextWrapper.java:258)
03-07 20:12:56.802: W/System.err(18401):    at com.sonrlabs.test.sonr.UserActionHandler.processUserCommand(UserActionHandler.java:153)
03-07 20:12:56.802: W/System.err(18401):    at com.sonrlabs.test.sonr.UserActionHandler.processAction(UserActionHandler.java:72)
03-07 20:12:56.802: W/System.err(18401):    at com.sonrlabs.test.sonr.AudioProcessorQueue.handleAction(AudioProcessorQueue.java:54)
03-07 20:12:56.802: W/System.err(18401):    at com.sonrlabs.test.sonr.AudioProcessorQueue.processAction(AudioProcessorQueue.java:33)
03-07 20:12:56.802: W/System.err(18401):    at com.sonrlabs.test.sonr.signal.SignalConstructor.processSignalIfMatch(SignalConstructor.java:50)
03-07 20:12:56.802: W/System.err(18401):    at com.sonrlabs.test.sonr.signal.TransmissionFinder.processSample(TransmissionFinder.java:29)
03-07 20:12:56.802: W/System.err(18401):    at com.sonrlabs.test.sonr.signal.TransmissionFinder.nextSample(TransmissionFinder.java:23)
03-07 20:12:56.802: W/System.err(18401):    at com.sonrlabs.test.sonr.signal.TransmissionPreprocessor.nextSample(TransmissionPreprocessor.java:38)
03-07 20:12:56.802: W/System.err(18401):    at com.sonrlabs.test.sonr.signal.AudioProcessor.nextSamples(AudioProcessor.java:22)
03-07 20:12:56.802: W/System.err(18401):    at com.sonrlabs.test.sonr.AudioProcessorQueue.run(AudioProcessorQueue.java:82)

我只想要出现Android Voice Command Prompt。我怎么能这样做?

2 个答案:

答案 0 :(得分:1)

似乎您的“设备”中没有人能够使用Action ACTION_VOICE_COMMAND处理该Intent。

您发布的代码没问题。这是从服务启动Intent的正确方法。

答案 1 :(得分:1)

你应该只是广播意图。然后系统抓住它并启动Voice命令应用程序。     Intent broadcast = new Intent();     broadcast.setAction(Intent.ACTION_VOICE_COMMAND);     sendBroadcast(广播);