我通过短信发送GPS数据。我正在使用abortBroadcast并在android清单android:优先级为接收器设置为1000.所以当应用程序运行移动设备没有接收除app.Please之外的其他消息的问题帮助我。
My code is as follows:
//This is Broadcast Receiver that I Registered in android manifest.
public class SimpleSmsReciever extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED"))
{
Bundle bundle = intent.getExtras();
if (bundle != null) {
Object[] pdusObj = (Object[]) bundle.get("pdus");
SmsMessage[] messages = new SmsMessage[pdusObj.length];
for (int i = 0; i < pdusObj.length; i++) {
messages[i] = SmsMessage.createFromPdu((byte[]) pdusObj[i]);
}
for (SmsMessage currentMessage : messages) {
sender = currentMessage.getDisplayOriginatingAddress();
msg =msg+currentMessage.getDisplayMessageBody();
}
this.abortBroadcast();
//Here Iam cancelling the broadcast.
}
}
答案 0 :(得分:0)
Iam searching for string KEY_SENDER in the message if it exists then I am using abortbroadcast.So the messages with KEY_SENDER as substring will not reach native inbox.so the other messages will be reach to inbox.
int intIndex = msg.indexOf("KEY_SENDER");
if(intIndex == - 1){
System.out.println("KEY_SENDER not found");
}
else
{
this.abortBroadcast();
}