Android Question SpeechToText library running in the background

Semendey

Member
Hello everyone.
I just started learning B4A and Android programming.
Now, based on the example from the SpeechToText library,
I made an application that contains a service, everything works as it should.
But as soon as I remove the application from the screen, the microphone stops listening.
How is it possible to make the microphone and, accordingly, SpeechToText work in the background?
Any help
 

drgottjr

Expert
Licensed User
Longtime User
you need to make your service a foreground service and set its foregroundservicetype to "mediaPlayback". you also need to add these permissions to the manifest:
"android.permission.FOREGROUND_SERVICE"
"android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK".
and probably turn off battery-saving options.
 
Upvote 0

Semendey

Member
Thank you.
I added to the manifest and it solved the problem:

SetActivityAttribute(voskservice, android:foregroundServiceType, "microphone")

I will also try to add to the manifest and those permissions that you specified.

The next task will be to make autostart at startup
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…