2011-08-12 5 views
15
ContentResolver cr = getContentResolver(); 
Cursor cur = cr.query(Uri.parse("content://sms/conversations/"), null,null,null, null);  

no funciona ¿por qué?¿Quiero buscar y ver conversaciones de sms?

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

permisos se han agregado.

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) 

Respuesta

16

finalmente consiguió lo que necesitaba!

ContentResolver contentResolver = getContentResolver(); 
final String[] projection = new String[]{"*"}; 
Uri uri = Uri.parse("content://mms-sms/conversations/"); 
Cursor query = contentResolver.query(uri, projection, null, null, null); 
2

No estoy seguro y aún no lo he intentado, pero creo que esto puede ser de su trabajo.

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

había encontrado esto antes de esta respuesta: How to delete an SMS from the inbox in Android programmatically?

+0

@but esto sólo muestra los mensajes recibidos no la envió onces ... y necesito saber por qué mi consulta en la tabla de conversación no se está ejecutando? como contatins – Harinder

27

Usted puede recuperar SMS bandeja de entrada:

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])); 
    } 
} 

se puede recuperar otros elementos enviados por el cambio de la URI.

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

Usted puede hacer eso con MMS también con URI:

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

Para SMS-MMS tanto:

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

¿Cómo se puede hacer esto sin usar el deprecat? ed 'startManagingCursor()'? – HEATH3N

1
String[] projection = {"thread_id", "MAX(date)", "COUNT(*) AS msg_count", "body"}; 
Cursor cursor = getContentResolver().query(Telephony.Sms.CONTENT_URI, projection, "thread_id) GROUP BY (thread_id", null, null);