Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

android - I want to fetch and view sms conversations?

ContentResolver cr = getContentResolver();
Cursor cur = cr.query(Uri.parse("content://sms/conversations/"), null,null,null, null);     

is not working why?

<uses-permission android:name="android.permission.READ_SMS" />

permissions have been added.

08-12 10:56:39.188: ERROR/AndroidRuntime(377): Caused by: android.database.sqlite.SQLiteException: near ",": syntax error: , while compiling: SELECT , body AS snippet FROM sms, (SELECT thread_id AS group_thread_id, MAX(date)AS group_date,COUNT(*) AS msg_count FROM sms GROUP BY thread_id) AS groups WHERE (sms.thread_id = groups.group_thread_id AND sms.date =groups.group_date)
08-12 10:56:39.188: ERROR/AndroidRuntime(377):     at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:143)
08-12 10:56:39.188: ERROR/AndroidRuntime(377):     at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:111)
08-12 10:56:39.188: ERROR/AndroidRuntime(377):     at android.content.ContentProviderProxy.bulkQuery(ContentProviderNative.java:279)
08-12 10:56:39.188: ERROR/AndroidRuntime(377):     at android.content.ContentProviderProxy.query(ContentProviderNative.java:298)
08-12 10:56:39.188: ERROR/AndroidRuntime(377):     at android.content.ContentResolver.query(ContentResolver.java:152)
08-12 10:56:39.188: ERROR/AndroidRuntime(377):     at com.GetMessages.GetConversations$FetchData.doInBackground(GetConversations.java:33)
08-12 10:56:39.188: ERROR/AndroidRuntime(377):     at com.GetMessages.GetConversations$FetchData.doInBackground(GetConversations.java:1)
08-12 10:56:39.188: ERROR/AndroidRuntime(377):     at android.os.AsyncTask$2.call(AsyncTask.java:185)
08-12 10:56:39.188: ERROR/AndroidRuntime(377):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:256)
See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

You can fetch sms-inbox:

Uri mSmsinboxQueryUri = Uri.parse("content://sms/inbox");
Cursor cursor1 = getContentResolver().query(mSmsinboxQueryUri,new String[] { "_id", "thread_id", "address", "person", "date","body", "type" }, null, null, null);
startManagingCursor(cursor1);
String[] columns = new String[] { "address", "person", "date", "body","type" };
if (cursor1.getCount() > 0) {
   String count = Integer.toString(cursor1.getCount());
   while (cursor1.moveToNext()){
       String address = cursor1.getString(cursor1.getColumnIndex(columns[0]));
       String name = cursor1.getString(cursor1.getColumnIndex(columns[1]));
       String date = cursor1.getString(cursor1.getColumnIndex(columns[2]));
       String msg = cursor1.getString(cursor1.getColumnIndex(columns[3]));
       String type = cursor1.getString(cursor1.getColumnIndex(columns[4]));
    }
}

You can fetch other sent items by changing the URI.

Uri mSmsinboxQueryUri = Uri.parse("content://sms/sent");

You can do that with MMS also with URI:

RECEIVED_MMS_CONTENT_URI = "content://mms/inbox";
SENT_MMS_CONTENT_URI = "content://mms/sent";

For SMS-MMS both:

Uri uri = Uri.parse("content://mms-sms/conversations/");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...