To get the pdu from a message, use a broadcast reciever, set the
intent filter in the manifest to recieve sms, you can get a pdu from a
message in the broadcast reciever as follows:
public void onReceive(Context context, Intent intent)
{
// if the abort command is issued this will execute when the
next message is received.
// The message will not be processed and this instance will be
removed as a receiver.
System.out.println("onRecieve message.....");
System.out.println("Intent action: "+intent.getAction());
if (intent.getAction().equals(ACTION_RECIEVED))
{
System.out.println("getting messages.");
// retrieve the received sms messages form the intent.
Bundle bundle = intent.getExtras();
if ( bundle==null)
{
System.out.println("Message bundle is null!");
return;
}
else
{
// retrieve all incoming messages that haven't been
processed.
// typically will be only one message per receive event.
Object[] pdusObj = (Object[]) bundle.get("pdus");
if ( pdusObj==null )
{
System.out.println("Message pdu's are null!");
return;
}
SmsMessage[] messages = new SmsMessage[pdusObj.length];
System.out.println("retrieving: "+pdusObj.length+"
messages.");
for (int i = 0; i<pdusObj.length; i++)
{
// create the message from the pdu
messages[i] = SmsMessage.createFromPdu ((byte[])
pdusObj
[i]);
System.out.println("Message: "+i+" "+messages
[i].getMessageBody());
System.out.println("Message from: "+messages
[i].getOriginatingAddress());
if (saveMessage)saveMessage(messages[i]);
}
}
}
}
On Feb 16, 9:48 pm, Hui <[email protected]> wrote:
> To SmsMessage, it only supports to parse deliver pdu into SmsMessage,
> but how to do a reverse operation (get a deliver pdu from a
> SmsMessage). On the other hand, there is a method getSubmitPdu to get
> a submit pdu from a submit message, but no reverse function.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---