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();
}
}
精彩评论