IntentReceiver组件不允许绑定到服务
这是我的代码:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.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);
}
}
}
当我尝试初始化 TextToSpeech
时收到错误。显然,在 BroadcastReceiver
中时我无法绑定到服务。有什么解决方法吗?
Here is my code:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论