BroadcastReceiver does not work for SMS_RECEIVED

I am trying to register BroadcastReceiver by activity programmatically using this code

br=new BroadcastReceiver() {                        
            private static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
            private static final String TAG = "cyb";

        @Override
        public void onReceive(Context context, Intent intent) {
            Toast.makeText(context, "ok", Toast.LENGTH_LONG).show();
             Log.e(TAG, "Intent recieved: " + intent.getAction());

                if (intent.getAction().equals(SMS_RECEIVED)) {
                    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.length > -1) {
                            Log.e(TAG, "Message recieved: " + messages[0].getMessageBody());
                        }
                    }
                }
        }
    };      

    IntentFilter inf=new IntentFilter("android.provider.Telephony.SMS_RECEIVED");
    inf.setPriority(999);
    registerReceiver(br, inf);

I also added this permission in AndroidManifest.xml

 <uses-permission android:name="android.permission.RECEIVE_SMS"/>

My application will not receive any notifications when receiving new SMS. I am using Android 4.2 using Hangouts and GoSMS

Update 2:

After uninstalling GOSMS, it worked. But I want to receive the SMS_RECEIVED intention action, even if the user has installed the GoSMS application or not. Is it possible? Any alternative solution?

+3
source share
1 answer

You also need to implement the MMS receiver + HeadlessSmsSendService + ComposeSmsActivity

. : http://android-developers.blogspot.fr/2013/10/getting-your-sms-apps-ready-for-kitkat.html

0

All Articles