0

我正在通过短信发送 GPS 数据。我正在使用 abortBroadcast 并且在 android manifest android:priority for receiver 设置为 1000。所以当应用程序运行移动时的问题没有收到除应用程序以外的其他消息。请帮助我。

        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.


            }
            }         
4

1 回答 1

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();
  }
于 2013-08-22T12:12:33.897 回答