I am aware that there are dozens of links on Stackoverflow and other sites about the SpeechRecognizer class and how to implement it. I have been through several of them and have searched for hours. Although there are examples of implementations in services, they don't seem to work for me.
My application has an activity, however it is only used for user settings and does not run when my service runs, which is called separately from the system. Thus my service does not have any main application thread to relate to in order to run/invoke the methods of the SpeechRecognizer class.
As it is stated in the android docs, here:
'This class's methods must be invoked only from the main application thread.'
When I run my code including the SpeechRecognizer.startListening(mSpeechRecognizerIntent) method which is in my service class I get the following error:
java.lang.RuntimeException: SpeechRecognizer should be used only from the application's main thread
Is there a way to solve this problem? I have read that the SpeechRecognizer can 'recognize speech while running in the background or from a service', I found that here:
Comparison of Speech Recognition use in Android: by Intent or on-thread?
So that is basically what I want I just can't seem to get the SpeechRecognizer started because I get the mentioned error. Could you also tell me whether it is necessary to call the following methods in the application's main thread (,which i don't have):
mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(this); mSpeechRecognizer.setRecognitionListener(new SpeechRecognitionListener());
My code is basically identical to the code in the top answer of this link: (without the IncomingHandler class, which I believe is only used to control the timing of the listener)
Android Speech Recognition as a service on Android 4.1 & 4.2
Would really appreciate some help, thanks in advance. This is my first android application so I am pretty new to it, please bear with me ;)