我有一个从Telecom接收数据短信的应用程序。在我的代码中,我在Activity中注册了动态Broadcastreceiver。它工作正常,但有时我丢失了一些短信,我不知道为什么。这是我的代码
IntentFilter mFilter = new IntentFilter(
"android.intent.action.DATA_SMS_RECEIVED");
mFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
mFilter.addDataAuthority("localhost", "my port");
mFilter.addDataScheme("sms");
if (smsReceiver == null)
smsReceiver = new SmsReceiverBroadcast();
context.registerReceiver(smsReceiver, intentFilter);
将BroadCast注册到活动后我等待60秒
long time = 0;
int delay = 200;
while (!Variable.getMessage && !finish
&& !Util.isTimeout(time, Timer)) {
Util.sleep(delay);
time += delay;
}
我的BroadCastReceiver:
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String str = "";
if (bundle != null && bundle.containsKey("pdus")) {
Object[] pdus = (Object[]) bundle.get("pdus");
if (pdus != null) {
String pduString = toHexString((byte[]) pdus[0]);
LogParams.pdu = (byte[]) pdus[0];
msgs = new SmsMessage[pdus.length];
for (int i = 0; i < msgs.length; i++) {
msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
if (msgs[i].getMessageBody() != null) {
str += msgs[i].getMessageBody().toString();
Variable.isReadPdu = true;
} else {
PduParser pduparser = new PduParser();
Pdu pdu = pduparser.parsePdu(pduString);
str += pdu.getDecodedText();
Variable.isReadPdu = true;
}
我的代码出了什么问题?