Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

android - How to use SMS content provider? Where are the docs?

I'd like to be able to read the system's SMS content provider. Basically I wanted to make an SMS messaging app, but it would only be useful if I could see past threads etc.

It seems like there's a content provider for this, but I can't find documentation for it - anyone know where that is?

Thanks

-------- edit -----------

Ok I found a way to get the sms inbox provider, and I just dumped all the column names in that provider, looks like this:

Uri uriSms = Uri.parse("content://sms/inbox");
Cursor c = context.getContentResolver().query(uriSms, null,null,null,null); 

// column names for above provider:
0: _id
1: thread_id
2: address
3: person
4: date
5: protocol
6: read   
7: status
8: type
9: reply_path_present
10: subject
11: body
12: service_center
13: locked

I'm just piecing this together from random threads I find around the net, I'm really wondering where this is all documented (if at all)?

Thanks again

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In addition to those u can see the list of fields in sms content provider by using following code:

private void displaySmsLog() {
    Uri allMessages = Uri.parse("content://sms/");
     //Cursor cursor = managedQuery(allMessages, null, null, null, null); Both are same
    Cursor cursor = this.getContentResolver().query(allMessages, null,
            null, null, null);

    while (cursor.moveToNext()) {
        for (int i = 0; i < cursor.getColumnCount(); i++) {
            Log.d(cursor.getColumnName(i) + "", cursor.getString(i) + "");
        }
        Log.d("One row finished",
                "**************************************************");
    }

}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...