IntentReceiver components are not allowed to bind to services
Here is my code:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.cont开发者_如何学Pythonent.Intent;
import android.speech.tts.TextToSpeech;
import android.telephony.SmsMessage;
import android.util.Log;
public class SmsBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Object[] rawMsgs = (Object[])intent.getExtras().get("pdus");
for (Object raw : rawMsgs) {
SmsMessage message = SmsMessage.createFromPdu((byte[])raw);
Log.v("[SMS]:", message.getMessageBody());
TextToSpeech tts = new TextToSpeech(context, null);
}
}
}
I get an error when I try to initialize TextToSpeech
. Apparently, I can't bind to services when in a BroadcastReceiver
. Is there any workaround for this?
精彩评论