2009-09-11 14 views

Respuesta

9

threadId debería ser el ID del SMS/MMS hilo que desea ver

Intent defineIntent = new Intent(Intent.ACTION_VIEW); 
defineIntent.setData(Uri.parse("content://mms-sms/conversations/"+threadId)); 
myActivity.startActivity(defineIntent); 

Ésta es la forma más sencilla que encontré

+0

¿Cómo obtengo el ID de hilo de un sms? – Janusz

+0

Intente buscar en el método findThreadIdFromAddress() aquí: http://code.google.com/p/android-smspopup/source/browse/trunk/SMSPopup/src/net/everythingandroid/smspopup/SmsPopupUtils.java –

+0

@paul_sns Dead enlazar. – VickyS

2

Cavé esto fuera de la fuente de la aplicación de mensajería (lines 311-315), así que estoy bastante seguro de que funcionará, pero no tengo ninguna experiencia con él.

// threadId should be the id of the sms/mms thread you want to view 
long threadId = 0; 
Intent i = new Intent("com.android.mms"); 
i.setData(
     Uri.withAppendedPath(
       i.getData(), Long.toString(threadId) 
     ) 
); 
i.setAction(Intent.ACTION_VIEW); 
+0

Creo que 'thread id' es diferente de 'sms id'? diferentes sms de una misma persona (cada uno tiene su propio id.) Pueden tener el mismo id. De subproceso. – n179911

4

Prueba este

int req_thread_id; 

Uri mSmsinboxQueryUri = Uri.parse("content://sms")); 
Cursor cursor1 = getContentResolver().query(
         mSmsinboxQueryUri, 
         new String[] { "_id", "thread_id", "address", "person", "date", 
           "body", "type" }, null, null, null); 

startManagingCursor(cursor1); 
if (cursor1.getCount() > 0) 
{ 
while (cursor1.moveToNext()) 
{ 

int thread_id = cursor1.getInt(1); 
String address; = cursor1.getString(cursor1 
          .getColumnIndex(columns[0])); 
if("your desired no".equals(address) 
req_thread_id = thread_id; 
} 
} 
Intent defineIntent = new Intent(Intent.ACTION_VIEW); 
defineIntent.setData(Uri.parse("content://mms-sms/conversations/"+req_thread_id)); 
myActivity.startActivity(defineIntent); 
0

Este fragmento es de un comentario en la respuesta aceptada. Publicando el método aquí para la posteridad.

public static long findThreadIdFromAddress(Context context, String address) { 
    if (address == null) 
     return 0; 

    String THREAD_RECIPIENT_QUERY = "recipient"; 

    Uri.Builder uriBuilder = THREAD_ID_CONTENT_URI.buildUpon(); 
    uriBuilder.appendQueryParameter(THREAD_RECIPIENT_QUERY, address); 

    long threadId = 0; 

    Cursor cursor = null; 
    try { 

     cursor = context.getContentResolver().query(
       uriBuilder.build(), 
       new String[] { Contacts._ID }, 
       null, null, null); 

     if (cursor != null && cursor.moveToFirst()) { 
      threadId = cursor.getLong(0); 
     } 
    } finally { 
     if (cursor != null) { 
      cursor.close(); 
     } 
    } 
    return threadId; 
} 
Cuestiones relacionadas