开发者

Parsing SMS PDU

开发者 https://www.devze.com 2023-02-25 00:42 出处:网络
Seems to be that I need to p开发者_如何转开发arse PDU byte array received during SMS BroadcastReceiver:

Seems to be that I need to p开发者_如何转开发arse PDU byte array received during SMS BroadcastReceiver:

@Override
public void onReceive(Context context, Intent intent) 
{ 
    Bundle bundle = intent.getExtras();
    Object[] pdus = (Object[]) bundle.get("pdus");
}

Can someone point me how to do it?

I know that PDUs can be handled using SmsMessage.createFromPdu((byte[]) pdus[i]) but it's not what I'm looking for. I need more precise control over pdu bytes.


I have found solution - there's nice Java and dot NET library (under Apache license), which handles all PDU related stuff - parsing and so on. It's SMSLib


@Override
public void onReceive(Context context, Intent intent) {
    Bundle bundle = intent.getExtras();

    SmsMessage[] msgs = null;

    if (bundle == null) return;

    Object[] pdus =  (Object[]) bundle.get("pdus");

    msgs = new SmsMessage[pdus.length];
    smsCount = msgs.length;
    String originalAddress;
    String tmpSmsBody;
    for (int i=0; i<msgs.length; i++){
        msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);

        // Original Address
        originalAddress = msgs[i].getOriginatingAddress();

        // Message body
        tmpSmsBody= msgs[i].getMessageBody().toString();
    }                
}
0

精彩评论

暂无评论...
验证码 换一张
取 消