Android stores text message confidence in the database. You can view/dbdata/databases/com. android. providers. telephony/mmssms. db. However, we cannot directly access the database, but can only access it through ContentProvider.
The following is the uri used to access the SMS database:
Content: // sms/inbox
Content: // sms/sent
Content: // sms/draft
Content: // sms/outbox sender
Content: // sms/failed to send
Content: // sms/queued list to be sent
The database fields are as follows:
_ Id: An auto-increment field starting from 1.
Thread_id number. the id of the same sender is the same.
Address sender's mobile phone number (based on the contact name ?)
The serial number in the person contact list. The stranger is null.
Date, in the unit of milliseconds, the time since)
Protocol, divided into: 0 SMS_RPOTO, 1 MMS_PROTO
Whether read is read. 0 is not read. 1 is read.
Status,-1 Receiving, 0 complete, 64 pending, 128 failed
Type
ALL = 0;
INBOX = 1;
SENT = 2;
DRAFT = 3;
OUTBOX = 4;
FAILED = 5;
QUEUED = 6;
Body text message content
Service_center text message service center number
Topic of the subject text message
Reply_path_present TP-Reply-Path
Locked
Query Information:
The data retrieval method is simple: in the Activity
Java code:
Uri uri = Uri. parse ("content: // sms/inbox ");
Cursor cur = this. managedQuery (uri, null );
If (cur. moveToFirst ()){
Do {
For (int j = 0; j <cur. getColumnCount (); j ++ ){
Info = "name:" + cur. getColumnName (j) + "=" + cur. getString (j );
Log. I ("===>", info );
}
} While (cur. moveToNext ());
}
ManagedQuery (Uri uri, String [] projection, String selection, String [] selectionArgs, String sortOrder) parameters are listed in the uri
Query field query field array, you can also put all the fields to be queried into one character
For example, new String [] {"_ id", "thread_id"} and new String [] {"_ id, thread_id"} are consistent.
Like SQL, field names are case-insensitive
The SQL condition character without the Where clause is like "_ id =? And thread_id =? Or type = '1 '"
Parameter parameter character array in the condition, one-to-one correspondence with the preceding Condition
Sort strings without Order by, such as _ id desc and type
If the parameter is null, the SQL query field is "*", and the related conditions are blank deletion information:
Java code:
This. getContentResolver (). delete (Uri. parse ("content: // sms"), "_ id =? ", New String [] {" 3 "});
Content: // sms in the Url is successfully replaced with content: // sms/, but the program reports an error in other URLs. For example, you must add the permission to content: // sms/inbox.
Java code:
<Uses-permission android: name = "android. permission. WRITE_SMS"> </uses-permission>
<Uses-permission android: name = "android. permission. READ_SMS"> </uses-permission>
Author "xSTARx"