Unable to receive SMS receive broadcast on Galaxy SIII running 4.1.1

霸气de小男生 提交于 2019-12-12 09:27:51

问题


I have this problem only on Samsung Galaxy SIII running Android 4.1.1. There is no problem on Samsung Galaxy Ace and Samsung Galaxy Y. The broadcast SMS received is not firing up, when SMS is received. No other SMS app is installed on the phone.

I am using the following code to receive the SMS broadcast

    smsReceiver = new BroadcastReceiver() {

    @Override
    public void onReceive(Context context, Intent intent) {

        Log.d(TAG, "Inside onReceive of smsReceiver");
        Bundle bundle = intent.getExtras();
        Object[] messages = (Object[]) bundle.get("pdus");
        SmsMessage[] sms = new SmsMessage[messages.length];
        // Create messages for each incoming PDU
        for (int n = 0; n < messages.length; n++) {
            sms[n] = SmsMessage.createFromPdu((byte[]) messages[n]);
        }
        for (SmsMessage msg : sms) {
            //do something
        }
    }
};

IntentFilter intentFilter = new IntentFilter();

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {

    intentFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY - 1);

} else {
    // set Interger.MAX_VALUE because other apps like Handcent are intercepting
    intentFilter.setPriority(Integer.MAX_VALUE);

}
intentFilter.addAction("android.provider.Telephony.SMS_RECEIVED");
// register receiver for receive SMS
registerReceiver(smsReceiver, intentFilter);

I have set the following permission in the Manifest

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

I don't have logcat access. I have spend last two days trying to find the cause in the maze of Android but no help.

来源:https://stackoverflow.com/questions/14801658/unable-to-receive-sms-receive-broadcast-on-galaxy-siii-running-4-1-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!