我有一个IncomingSmsReceiver类,它接收一条短信,但问题是接收文本消息要花一些时间,我知道BroadcastReceiver类会在监听10秒钟以上时自动停止该过程,有什么办法禁用它?
这是我的代码:
public class IncomingSmsReceiver extends BroadcastReceiver {
private ShowDialogInterface callback;
public void onReceive(Context context, Intent intent) {
if (Telephony.Sms.Intents.SMS_RECEIVED_ACTION.equals(intent.getAction())) {
String messageBody = "no data";
String messageFrom = "no data";
for (SmsMessage smsMessage : Telephony.Sms.Intents.getMessagesFromIntent(intent)) {
messageBody = smsMessage.getMessageBody();
messageFrom = smsMessage.getDisplayOriginatingAddress();
}
if(callback != null) {
callback.smsDetails(messageFrom, messageBody);
}
}
}
public void registerReceiver(ShowDialogInterface receiverCallback) {
this.callback = receiverCallback;
}
// Show different UI elements to notifying the user of an incoming SMS
public interface ShowDialogInterface {
void smsDetails(String from, String message);
}
}
这是我的调试错误: enter image description here
最好的问候,
Noob Android_dev
答案 0 :(得分:0)
您可以从BroadcastReceiver启动服务,并在其中进行所有工作。这是做这些事情的标准方法。