2012-02-25 22 views
8

Tüm SMS'leri gelen kutusundan silmek istediğim bir uygulama üzerinde çalışıyorum. Bunun için aşağıdaki kodu kullandım.Android'de programlı olarak gelen tüm sms nasıl silinir?

Uri uriSms = Uri.parse("content://sms/inbox"); 
Cursor c = getContentResolver().query(uriSms, null,null,null,null); 
int id = c.getInt(0); 
int thread_id = c.getInt(1); //get the thread_id 
getContentResolver().delete(Uri.parse("content://sms/conversations/" + thread_id),null,null); 

Bu kod çalışmıyor. Aynı şeyi yapmak için herhangi bir yolu var mı?

+0

http://stackoverflow.com/questions/419184/how-to-delete-an-sms-from-the-inbox-in-android- olduğunu Programsal olarak –

cevap

6

silme uri "content://sms/" + id;

Uri inboxUri = Uri.parse("content://sms/inbox"); 
int count = 0; 
Cursor c = context.getContentResolver().query(inboxUri , null, null, null, null); 
while (c.moveToNext()) { 
    try { 
     // Delete the SMS 
     String pid = c.getString(0); // Get id; 
     String uri = "content://sms/" + pid; 
     count = context.getContentResolver().delete(Uri.parse(uri), 
       null, null); 
    } catch (Exception e) { 
    } 
} 
return count; 
+0

bu, tek bir mesajlaşma mı yoksa bir konuşma mı? –

0
//delete all call logs 
Uri callLog = Uri.parse("content://call_log/calls"); 
int rs1 = getContentResolver().delete(callLog, null, null); 

//delete all sms 
Uri inboxUri = Uri.parse("content://sms/");  
int rs2 = getContentResolver().delete(inboxUri, Sms._ID + "!=?", new String[]{"0"}); 
İlgili konular