Start from broadcast receiver

368 views
Skip to first unread message

nuno

unread,
Jul 8, 2009, 10:06:46 AM7/8/09
to TTS-for-Android
Hi all,

I am trying to start TTS from a broadcast receiver and it as document
an intent receiver can't bind the service.
Is there a work around, I can't figure out how to start the service
using startService(Intent, Bundle) any tips?

Thanks,

jphu...@googlemail.com

unread,
Jul 9, 2009, 11:25:17 AM7/9/09
to TTS-for-Android
Hi,

I'm having the same problem.

I guess, like me, you're passing in the Context from the
BroadcastReceiver's onReceive() method. The problem is that an
IntentReceiver is given a ReceiverRestrictedContext object which means
they cannot start services.

I'm not sure what the work around to this is, I can't see any way of
getting an unrestricted Context object and the TTS class requires a
Context object in all constructors.

Please let me know if you find a work around.

John

jphu...@googlemail.com

unread,
Jul 9, 2009, 11:36:10 AM7/9/09
to TTS-for-Android
Hi again,

sorted it!

you need to create a new context object from the TTS package context,
like so -

Context myContext = ctx.createPackageContext("com.google.tts", 0);

where ctx is the context from your BroadcastReceiver. Now use
myContext in your TTS constructor.

John

On Jul 9, 4:25 pm, "jphuns...@googlemail.com"

nuno

unread,
Jul 9, 2009, 1:15:10 PM7/9/09
to TTS-for-Android
Thanks! you are 5 stars I have spent all day doing refresh to this
hoping someone would answer :D
Now of to test it.

On Jul 9, 4:36 pm, "jphuns...@googlemail.com"
Reply all
Reply to author
Forward
0 new messages