2012-02-25 10 views
8

मैं एक ऐसे एप्लिकेशन पर काम कर रहा हूं जिसमें मैं इनबॉक्स से सभी एसएमएस हटाना चाहता हूं। इसके लिए मैंने निम्नलिखित कोड का उपयोग किया है।एंड्रॉइड में प्रोग्रामेटिक रूप से इनबॉक्स से सभी एसएमएस कैसे हटाएं?

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

यह कोड काम नहीं करता है। क्या ऐसा करने का कोई तरीका है?

+0

http://stackoverflow.com/questions/419184/how-to-delete-an-sms-from-the-inbox-in-android- प्रोग्रामेटिक –

उत्तर

6

हटाने 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

यह सिंगल मैसेज या कनवर्जन के लिए है? –

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"}); 
संबंधित मुद्दे