Android删除短信的方法

来源:互联网 发布:淘宝ued官网 编辑:程序博客网 时间:2024/04/29 11:38

1.删除短信的函数,一条一条的删除所有短信

[java] view plaincopy
  1. /* 
  2.  * Delete all SMS one by one 
  3.  */  
  4. public void deleteSMS() {  
  5.     try {  
  6.         ContentResolver CR = getContentResolver();  
  7.         // Query SMS  
  8.         Uri uriSms = Uri.parse("content://sms/sent");  
  9.         Cursor c = CR.query(uriSms,  
  10.                 new String[] { "_id""thread_id" }, nullnullnull);  
  11.         if (null != c && c.moveToFirst()) {  
  12.             do {  
  13.                 // Delete SMS  
  14.                 long threadId = c.getLong(1);  
  15.                 CR.delete(Uri.parse("content://sms/conversations/" + threadId),  
  16.                         nullnull);  
  17.                 Log.d("deleteSMS""threadId:: "+threadId);  
  18.             } while (c.moveToNext());  
  19.         }  
  20.     } catch (Exception e) {  
  21.         // TODO: handle exception  
  22.         Log.d("deleteSMS""Exception:: " + e);  
  23.     }  
  24. }  

 

2.在AndroidManifest.xml中增加读取短信的权限

[xhtml] view plaincopy
  1. <uses-permission android:name="android.permission.READ_SMS" />  
  2. <uses-permission android:name="android.permission.WRITE_SMS" />