2015-03-31 74 views
0

我想以編程方式從我的android設備上刪除1條短信。這是我目前使用的代碼。如何在android中以編程方式刪除SMS

private void DeleteSMS(int SmsId){ 
     Cursor c = getContentResolver().query(Uri.parse("content://sms/"),new String[] {"_id", "thread_id", "address", "body" }, null, null, null); 
     while (c.moveToNext()) { 
      try { 
        int pid = Integer.valueOf(c.getString(0));; // Get id; 
        String smsMessage = c.getString(3); 
        if (pid == SmsId) 
        { 
         String uri = "content://sms/"+pid; 
         int rows = getContentResolver().delete(Uri.parse(uri), null, null); 
         Toast.makeText(context, rows+" Message Deleted", Toast.LENGTH_LONG).show(); 
         break; 
        } 
      } catch (Exception e) { 
        Log.v("exception","occurred"); 
      } 
     } 
    } 

getContentResolver().delete執行DELETE語句後,將返回的行的影響爲0

+0

可能出現[以編程方式刪除Android SMS]的副本(http://stackoverflow.com/questions/8614211/deleting-android-sms-programatically) – Gattsu 2015-03-31 07:03:09

回答

相關問題