开发者

IntentReceiver components are not allowed to bind to services

开发者 https://www.devze.com 2023-02-10 16:44 出处:网络
Here is my code: import android.content.BroadcastReceiver; import android.content.Context; import android.cont开发者_如何学Pythonent.Intent;

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

精彩评论

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