Receipt of long SMS messages scattered on androids



  • I'm writing a little app, one of the functions is to process messages.

    I took the code to get sms messages. It's working, but when you get a long sms it's broken into several parts. We need to collect all parts of one sms in one line and check that the message has been fully received.

    Looking for a few options, but there's a mass in which the consignor's number is used as a key, which allows all parts of the message to be collected in one line, but does not guarantee the receipt of all parts sms.

    I studied PDU documentation but I couldn't understand some things.

    1. How do you know if the message is broken?
    2. How do you know the number of parts?
    3. How do you know the part of the process now?

    Please.

    public class SMSMonitor extends BroadcastReceiver {
        private static final String ACTION = "android.provider.Telephony.SMS_RECEIVED";
    
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent != null && intent.getAction() != null && ACTION.compareToIgnoreCase(intent.getAction()) == 0) {
            Object[] pduArray = (Object[]) intent.getExtras().get("pdus");
            SmsMessage[] messages = new SmsMessage[pduArray.length];
            for (int i = 0; i < pduArray.length; i++) {
                messages[i] = SmsMessage.createFromPdu((byte[]) pduArray[i]);
            }
            StringBuilder bodyText = new StringBuilder();
            for (SmsMessage message : messages) {
                bodyText.append(message.getMessageBody());
            }
            String body = bodyText.toString();
            Observer.getInstance().send(new SmsEvent(body));
            abortBroadcast();
        }
    }
    

    }



  • I'll give you an approximate algorithm.
    Let's say there's a line. pdu:

    0791979290F3440B919778563412F000085190422124618C050003F5041D043E47044C002C00200443043B0438040430002C002004443

    where:

    079197729290F3 SCA

    44 - ProtocolDataUnitType

    0B919778563412F0 - OriginatorAdrress

    00 - ProtocolIdentifier

    08 - DataCodingScheme

    519042212461 - ServiceCenterTimeStamp

    8C - UserDataLength

    050003F50201 - UDHI

    041D0447044C002C00200443043B043804460430002C00444043E0430044C004C00200430043C04044204350A0430002C000

    That's what you're interested in in in UDHI:050003F50201

    02 - is the number of messages, 01 - Serial number.
    Determine what it is. UDHI inside UserData Yes, you can. ProtocolDataUnitType - in our case. 44(Hex). Yes hex- we'll put it in the light and see the meaning. 6 Bita, if he's equal. 1Then UserData contained UDHI

    I hope I can help you with this difficult protocol.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2