How to make Google Now run continually in the background on Android
Asked Answered
B

1

16

I have a app idea in mind, but I haven't been able to figure out one part yet. In Google Now on Android, it gives you the following options to search:

  1. Type to search
  2. Click microphone to say your search
  3. Or just Say "Google" to make the voice search begin.

I'd like to know how they made #3 work. I need to have a keyword, that when said, initiates the voice search.

I imagine they have some type of background running service constantly listening for voice actions. Does anyone know how this is achieved?

Here is a image of the Google Now app:

enter image description here

Bank answered 25/4, 2013 at 16:4 Comment(2)
You want to know how they make it continuous or you want to make Google Now continuous.Platino
I want to know how to do what they did, but for my own app. So, in other words, how can i pick up a keyword someone may have said....but without ever having to click on the microphone buttonBank
P
4

You can write a service and then use createSpeechRecognizer in that service. For a complete service code for this you can find the answer at Android Speech Recognition as a service on Android 4.1 & 4.2

Platino answered 25/4, 2013 at 17:12 Comment(14)
Thanks so much! I had to tweak it just a little, but it worked like a charm!Bank
I also posted a code for bluetooth headset. If you want to use it you can find it at my answer at #14991658Platino
I'm still seeing a problem with Jellybean devices. After OnResults() is called, I call mSpeechRecognizer.startListening(mSpeechRecognizerIntent); Which should let me continue listening for more voice commands. On Jellybean after a few commands it just stops and onBeginningOfSpeech is never called again until I restart the app...whereas versions less than Jellybean work...any ideas?Bank
sorry...i hit enter thinking it would do a newline...not submit...I've updated the comment aboveBank
Instead of mSpeechRecognizer.startListening(mSpeechRecognizerIntent); You should send the MSG_RECOGNIZER_START_LISTENING to the message handler. Read the question in that link and you see why we need a work around. Also you should send MSG_RECOGNIZER_START_LISTENING on error.Platino
I edited my answer at the above link to send a message instead of calling startListeningPlatino
That still doesn't work. When you send the message MSG_RECOGNIZER_START_LISTENING the variable "mIsListening" is still true. So it never calls "startListening". I then tried forcing the variable to false to see what would happen...and the same problem persisted. It stops listening.Bank
@KentAndersen if you got this to work can you please post a sample code? am trying something similar as well.Anton
@Anton yes. I did. But just by using the supplied link in the answer. I ultimately turned off the feature because it was a major battery drain.Bank
okay. Did you manage to get a work around to integrate voice recognition in your app? am just looking for a sample working code because with the posted answer am running into lot of errors :(Anton
Hey, I've been looking at the code in the answer...and I'm really confused by it, especially IncomingHandler.class. Can you explain a little bit about what is happening there? I've been trying for almost 3 hours now! Thanks so much! :)Fatherly
The speech recognizer methods has to be called in the UI thread. Thus you need the IncomingHandler class since handleMessage method is called in the UI thread.Platino
Can I use speech recognizer in a separate service in a separate thread? Thanks!Fatherly
Anyone know if you can do this in ios?Indubitable

© 2022 - 2024 — McMap. All rights reserved.