Android Question TTS during notifications. Is it possible?

Straker

Active Member
Licensed User
Longtime User
Is it possible to use TTS inside a service in order to add some vocal message to a notification?
I've done some test but I can hear the message only when the main activity is show. When only the service is running I get only the notification without spoken message.

Probably I should start an 'invisible' activity with CallSubDelayed, use TTS and then terminate it. But I'm wondering if it is possible to do everything from then service...
 

Straker

Active Member
Licensed User
Longtime User
Thank you, Erel. Always very kind.

I'd like to explain the problem a little better.
I have a service with a socket that every 5 minutes or so connects to a server and collects some data. If everything is fine, the app will do nothing and reschedules itself in 5 minutes.
But if in the collected data there is some sort of alarm, it will emit a notification.
I'd like to enforce the notification with more sound and a voice describing the alarm.

Playing with services and notifications I noticed that TTS works only when the activity is running and not when it's called from the service (I've got TTS in a .bas module).

It's not a problem for my app, it was just curiosity.
I'll do some test with Barx's custom notification library.

Thanx again!
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
Thank you, Erel. Always very kind.

I'd like to explain the problem a little better.
I have a service with a socket that every 5 minutes or so connects to a server and collects some data. If everything is fine, the app will do nothing and reschedules itself in 5 minutes.
But if in the collected data there is some sort of alarm, it will emit a notification.
I'd like to enforce the notification with more sound and a voice describing the alarm.

Playing with services and notifications I noticed that TTS works only when the activity is running and not when it's called from the service (I've got TTS in a .bas module).

It's not a problem for my app, it was just curiosity.
I'll do some test with Barx's custom notification library.

Thanx again!
Custom Notification has been superseded by Notification Builder. This one is a lot more powerful.
 
Upvote 0
Top