Pdu in Android

Source: Internet
Author: User

The SMS received by the Android device is in the form of a pdu (protocol description unit ). Android. telephony. gsm. the SmsMessage class can store SMS-related information. We can also create a SmsMessage instance from the received pdu, the Toast interface component displays the received SMS message text in the form of system notifications.

A pdu is a "protocol discription unit", which is the industry format for an SMS message. because SMSMessage reads/writes them you shouldn't need to disect them. A large message might be broken into vertex, which is why it is an array of objects.


Public class SMSReceiver extends BroadcastReceiver
{
/* This method is triggered when you receive the text message */
Public void onReceive (Context context, Intent intent)
{
Bundle bundle = intent. getExtras ();
Object messages [] = (Object []) bundle. get ("pdus ");
SmsMessage smsMessage [] = new SmsMessage [messages. length];
For (int n = 0; n <messages. length; n ++)
{
SmsMessage [n] = SmsMessage. createFromPdu (byte []) messages [n]);
}
// Generate a Toast
Toast toast = Toast. makeText (context, "SMS content:" + smsMessage [0]. getMessageBody (), Toast. LENGTH_LONG );
// Set the toast display position
// Toast. setGravity (Gravity. TOP | Gravity. LEFT, 0,200 );
// Display the Toast
Toast. show ();
}
}
 
Author: Turning to tears

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.