my application gives error that BroadcastReceiver component are not allowed to bind to service. I am calling broadcast reciver when sms arrived and text will converted in to voice. my reciver called properly.
but My code give error like
FATAL EXCEPTION: main Process: texttospeech.tts.com.tts, PID: 12811 java.lang.RuntimeException: Unable to start receiver texttospeech.tts.com.tts.ttsBroadcast: android.content.ReceiverCallNotAllowedException: BroadcastReceiver components are not allowed to bind to services at android.app.ActivityThread.handleReceiver(ActivityThread.java:2618) at android.app.ActivityThread.access$1700(ActivityThread.java:148) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1369) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5312) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696) Caused by: android.content.ReceiverCallNotAllowedException: BroadcastReceiver components are not allowed to bind to services at android.app.ReceiverRestrictedContext.bindService(ContextImpl.java:215) at android.speech.tts.TextToSpeech.connectToEngine(TextToSpeech.java:800) at android.speech.tts.TextToSpeech.initTts(TextToSpeech.java:770) at android.speech.tts.TextToSpeech.(TextToSpeech.java:723) at android.speech.tts.TextToSpeech.(TextToSpeech.java:702) at android.speech.tts.TextToSpeech.(TextToSpeech.java:686) at texttospeech.tts.com.tts.ttsBroadcast.onReceive(ttsBroadcast.java:23) at android.app.ActivityThread.handleReceiver(ActivityThread.java:2611) at android.app.ActivityThread.access$1700(ActivityThread.java:148) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1369) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5312) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
this is my code
ttsBroadcast.java
public class ttsBroadcast extends BroadcastReceiver implements TextToSpeech.OnInitListener {
private TextToSpeech tts;
private String msg;
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context,"sms recived",Toast.LENGTH_LONG).show();
tts = new TextToSpeech(context,this);
tts.speak(msg,TextToSpeech.QUEUE_FLUSH,null);
}
@Override
public void onInit(int i) {
tts.setLanguage(Locale.ENGLISH);
}
}