Android SMS Format

Source: Internet
Author: User
the permissions required by Android SMSJava code <uses-permission android:name= "Android.permission.READ_SMS"/> <uses-permission android:name= " Android.permission.RECEIVE_SMS "/>

Second, SMS send
The class related to the short message send is: Smsmanager.
Java Code smsmanager.sendtextmessage (destinationaddress, scaddress, text, sentintent, deliveryintent);
Parameter description:
Destinationaddress the "address" to "send" to
Scaddress is the service center address or null to use the current default SMSC
Text to send
Sentintent if not NULL this pendingintent be broadcast when the ' is sucessfully sent, or failed. The result code is ACTIVITY.RESULT_OK for success, or one of these errors:result_error_generic_failure result_error_ Radio_off RESULT_ERROR_NULL_PDU. The per-application based SMS control checks sentintent. If Sentintent is NULL the caller would be checked against all unknown applications, which cause-smaller number of SMS to be Sent in checking period.
Deliveryintent if not NULL this pendingintent be broadcast when the "is" delivered to the recipient. The raw PDU of the status is in the extended data ("PDU").
Two of these pendingintent modes are:
Java code pendingintent sentintent = Pendingintent.getbroadcast (this, 0, new Intent ("Sms_sent"), 0); Intent deliveryintent = pendingintent.getbroadcast (this, 0, new Intent ("sms_delivered"), 0);
and registers the receiver, according to Getresultcode () to judge:
Java code registerreceiver (sendreceiver); Registerreceiver (Deliveredreceiver);

Third, SMS reception

Based on the intent of the Android.provider.Telephony.SMS_RECEIVED broadcast at the time of reception. We can extend a broadcastreceiver to receive SMS.
The passed intent contains PDUs data. The relevant code is as follows:
Java code Bundle Bundle = Intent.getextras ();        Object[] PDUs = (object[]) bundle.get ("PDUs");        smsmessage[] msgs = new Smsmessage[pdus.length];   for (int i = 0; i < pdus.length i++) {Msgs[i] = SMSMESSAGE.CREATEFROMPDU ((byte[)) pdus[i]); }

Four, the use of contentobserver monitoring SMS database

The above method is not able to update and delete SMS, to do these operations need to use Contentobserver to monitor the changes in the SMS database to carry out related operations.
1. Contenturi of SMS Database
Java code Public final static String Sms_uri_all = "content://sms/"; 0 public Final static string sms_uri_inbox = "Content://sms/inbox";//1 public final static string sms_uri_send = "Co Ntent://sms/sent ";//2 public final static string sms_uri_draft =" Content://sms/draft ";//3 public Final static string Sms_uri_outbox = "Content://sms/outbox";//4 public final static String sms_uri_failed = "content://sms/failed";//5 pub LIC final static String sms_uri_queued = "content://sms/queued";//6
2. SMS Main structure:
Java Code    _id =>  Short message serial number   such as 100   thread_id =>  dialog serial number   like 100    address =>  Sender Address, mobile phone number. such as +8613811810000   person =>  sender, Return a number is the number of the contact list, the stranger is null   date =>  date   long type. such as 1256539465022  
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.