Sms receiver only works on verizon devices

385 views Asked by At

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.

On any other carrier though, it's a mess.

On AT&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.

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.

Service

   @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);
    }

Receiver

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 < 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);
                    }
                }
            }
    }
    }
};

I use these imports in the app,

import android.telephony.SmsMessage;
import android.telephony.TelephonyManager;

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?

UPDATE 1 According to http://developer.android.com/reference/android/telephony/gsm/package-summary.html its not due to not using the gsm specific imports.

ANSWER 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

1

There are 1 answers

0
r2DoesInc On BEST ANSWER

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