如何避免短信到达Android的特定应用程序的本机收件箱

时间:2013-08-21 11:31:46

标签: android

我通过短信发送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.


            }
            }         

1 个答案:

答案 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();
  }