开发者

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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜