Examples of Android get SMS conversation list _android

Source: Internet
Author: User

There is no formal content provider available for SMS in Android, and no definition is provided in official documents. However, you can still define your own URI, and then query the content of the text. For example, Conetent://sms is the path where all text messages are located.

To classify text messages by conversation, I originally queried all messages and then sorted them by thread_id. The system's own message program contains a session display interface, each entry contains: contact person, number of SMS, the first text message and so on. When my program handles more text messages, it becomes very slow to query all the text messages at a time. (It will be slower if you add query contact information for each session)

Read the system text message code, found that it can only query the information of the session, rather than query out all the text message content. Because some of the code is not found, never know how it can be done. After reading the code of Telphony provider, we know one or two.

In fact, the SMS database (MMSSMS.DB) does not have a table to store session information. The content provider provided by the system actually supports querying session information directly. However, its implementation, not through a ready-made table, but through the SQL statements, from a number of tables to complete the data. There is also a mention of this implementation in this post.

Implementation of the way is not to delve into, after all, I am not familiar with the SQL query. Release the direct use method:

Gets the URI of the session information

  Java code

public static final Uri Mmssms_full_conversation_uri = Uri.parse ("content://mms-sms/conversations");
public static final Uri Conversation_uri = Mmssms_full_conversation_uri.buildupon ().
Appendqueryparameter ("Simple", "true"). Build ();
public static final Uri Mmssms_full_conversation_uri = Uri.parse ("content://mms-sms/conversations");
public static final Uri Conversation_uri = Mmssms_full_conversation_uri.buildupon ().
Appendqueryparameter ("Simple", "true"). Build ();

By specifying Simple=true, you can get an approximate session data that contains the following:

  Java code

private static final int ID = 0;
private static final int DATE = 1;
private static final int message_count = 2;
private static final int recipient_ids = 3;
private static final int snippet = 4;
private static final int snippet_cs = 5;
private static final int READ = 6;
private static final int TYPE = 7; 
private static final int ERROR = 8;
private static final int has_attachment = 9;

The column name is:

 Java code

private static final string[] All_threads_projection = {
"_id", "date", "Message_count", "Recipient_ids",
"s Nippet "," Snippet_cs "," read "," error "," Has_attachment "
};

which

1, Message_count the number of messages for the session;

2, Recipient_ids is the contact ID, this ID is not the _id in the Contact table, but points to the Id,canonical_ in the table canonical_addresses Addresses This table is also located in Mmssms.db, which maps recipient_ids to a phone number, that is to say, the final access to contact information, or through the phone number;

3, snippet for the last received/sent SMS;

The type of each data is roughly:

  Java code

Long id = cursor.getlong (ID);
Long date = Cursor.getlong (date);
Long Msgcount = Cursor.getlong (message_count);
String recipids = cursor.getstring (recipient_ids);
String snippet = cursor.getstring (snippet);
Long Snippetcs = Cursor.getlong (snippet_cs);
Long read = Cursor.getlong (read);
Long type = Cursor.getlong (type);
Long error = Cursor.getlong (error);
Long Hasattach = Cursor.getlong (has_attachment);
Long id = cursor.getlong (ID);
Long date = Cursor.getlong (date);
Long Msgcount = Cursor.getlong (message_count);
String recipids = cursor.getstring (recipient_ids);
String snippet = cursor.getstring (snippet);
Long Snippetcs = Cursor.getlong (snippet_cs);
Long read = Cursor.getlong (read);
Long type = Cursor.getlong (type);
Long error = Cursor.getlong (error);
Long Hasattach = Cursor.getlong (has_attachment);

The above content is small make up to everyone introduced Android get SMS conversation list of all the narration, I hope you like.

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.