title: Sms receiver only works on verizon devices
body: <p>I have an app that listens to incoming messages, and if the originating sender is the one specified by the user, it then reacts accordingly, showing a special alert and aborting the broadcast, preventing it from reaching the inbox. On Verizon, it works perfectly. I've sent over 300 without any issue, as have a few other testers.</p>
  
  <p>On any other carrier though, it's a mess.</p>
  
  <p>On AT&amp;T, the broadcast is never aborted and it shows up in the sms inbox.
  On Sprint, the broadcast is aborted, but it never gets beyond that. The AlertActivity intent  is never called, nor either of the toast messages I put to check.
  On T-Mobile, the broadcast is never aborted and it shows up in the sms inbox.</p>
  
  <p>I have the receiver done in java rather than registered in the Manifest because I register it in a service which is started on app launch and on BOOT_COMPLETED.</p>
  
  <p>Service</p>
  
  <pre><code>   @Override
      public int onStartCommand(Intent intent, int flags, int startId) {
          return START_STICKY;
      }
  
      public void startService() {
          IntentFilter SMSfilter = new IntentFilter("android.provider.Telephony.SMS_RECEIVED");
          this.registerReceiver(Receiver.br, SMSfilter);
      }
  </code></pre>
  
  <p>Receiver</p>
  
  <pre><code>static public BroadcastReceiver br = new BroadcastReceiver() {
  
      @Override
      public void onReceive(Context context, Intent intent) { 
      Bundle bundle = intent.getExtras();
      if (bundle != null) {
              Object[] pdus = (Object[]) bundle.get("pdus");
              final SmsMessage[] messages = new SmsMessage[pdus.length];
              for (int i = 0; i &lt; pdus.length; i++) {
                  messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
                  if (messages[i].getOriginatingAddress().equals(Test.SENDER)) {
                      abortBroadcast();
                      String[] body = messages[i].getDisplayMessageBody().split(" ", 7);
                      if (body[0].equals("test")) {
                          test = true;
                      }
                      cat = body[1];
                      level = body[2];
                      urgency = body[3];
                      certainty = body[4];
                      carrier = body[5];
                      message = body[6];
                      intent = new Intent(context, AlertActivity.class);
                      Bundle b = new Bundle();
                      b.putString("title", cat);
                      b.putString("certainty", certainty);
                      b.putString("urgency", urgency);
                      b.putString("level", level);
                      b.putString("message", message);
                      b.putBoolean("test", test);
                      intent.putExtras(b);
                      intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);                           TelephonyManager manager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
                      carrierName = manager.getNetworkOperatorName();
                      if (carrierName.replaceAll(" ", "").equals(carrier)) {
                          context.startActivity(intent);
                      } else {
                          //testing
                          toast(carrierName.replaceAll(" ", ""), context);
                      }
                  }
              }
      }
      }
  };
  </code></pre>
  
  <p>I use these imports in the app,</p>
  
  <pre><code>import android.telephony.SmsMessage;
  import android.telephony.TelephonyManager;
  </code></pre>
  
  <p>I know that there is a gsm version of these as well, which I don't use. Could this be why the app isn't detecting the incoming messages on the gsm carriers?</p>
  
  <p><strong>UPDATE 1</strong>
  According to <a href="http://developer.android.com/reference/android/telephony/gsm/package-summary.html" rel="nofollow">http://developer.android.com/reference/android/telephony/gsm/package-summary.html</a> its not due to not using the gsm specific imports.</p>
  
  <p><strong>ANSWER</strong>
  Got it. 
  It has to do with how the incoming message senders number is read. 
  On the verizon device it would register as xxxxxxx on others, +1xxxxxxx. Added an option to acces Test.SENDER or Test.SENDER_LAME which is +1xxxxxxx</p>