Android get the latest send SMS basic information, no one

Source: Internet
Author: User

Registered:

Getcontentresolver (). Registercontentobserver (
Uri.parse ("Content://sms"), True,
New Smsobserver (This, new Handler ()));

Listening:

Used to detect the sending of SMS
public class Smsobserver extends Contentobserver {
Private context context;

Public Smsobserver (context context, Handler Handler) {
Super (handler);
This.context = context;
}

public void OnChange (Boolean selfchange) {
cursor cursor = getcontentresolver (). Query (Uri.parse ("Content://sms/outbox"), NULL, NULL, NULL, NULL);
Traverse query results to get the text message that the user is sending
if (Cursor.movetolast ()) {
StringBuffer sb = new StringBuffer ();
Get the content of a text message
Sb.append (Cursor.getstring (Cursor.getcolumnindex ("body"));
Get the sending time of a text message
if (Issendmail && sb.tostring (). Equals ("")) {
Issendmail = false;
Operation
}
}
}

}

Note: The onchange may have been callback two times. So you need to take advantage of tag tag control to go only one operation.

Android get the latest send SMS basic information, no one

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.