简体   繁体   中英

How can I launch an ACTION_VOICE_COMMAND Intent from a Service?

I have the following code to launch an Intent in my service:

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

I get the error

No Activity Found to Handle Intent

Here is the 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)

I just want the Android Voice Command Prompt to appear. How can I do this?

You should simply broadcast the intent. then the system grabs it and starts the Voice command app. Intent broadcast = new Intent(); broadcast.setAction(Intent.ACTION_VOICE_COMMAND); sendBroadcast(broadcast);

It seems that noone in your "device" is able to handle that Intent with Action ACTION_VOICE_COMMAND.

The code you posted is ok. That's the right way of launching Intents from a Service.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM