Retrieve SMS with User Data Header (UDH) on Androi

2019-08-24 12:01发布

问题:

I am developing an Android application that should retrieve SMS with User Data Header (UDH). Messages with UDH are invisible for standard Android SMS messenger. I use "06050415810000" UDH for testing ("06" - header length, "05" - header type, "04" - length of the rest of the header, "1581" - destination port, "0000" - src port). Device with Samsung OS has retrieved message with such header and the message was shown in the Inbox folder (but it was not possible to open the message). Device with Android OS is not showing it (it's normal), but my app can't catch invisible SMS. I have the following code to catch SMS:

public class SmsReceiver extends BroadcastReceiver {

public Class<?> delegate = null;

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

        AppManager.setSmsMessage(messages[0]);

        if (delegate != null) {
            Intent di = new Intent(context, delegate);
            di.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
            di.putExtra("SMS", messages[0].getPdu());
            context.startActivity(di);
        }

    }
}

And this is my manifest file:

    <receiver
        android:name=".services.SmsReceiver">
        <intent-filter>
            <action android:name="android.provider.Telephony.SMS_RECEIVED" />
            <action android:name="android.intent.action.DATA_SMS_RECEIVED"/>                 
        </intent-filter>
    </receiver>

The app retrieve only messages without UDH.

回答1:

You need the RECEIVE_SMS permission

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


标签: android sms