1. Delete SMS function, delete all text messages in one line
/** Delete all SMS one by one*/ Public voiddeletesms () {Try{contentresolver CR=Getcontentresolver (); //Query SMSUri urisms = Uri.parse ("Content://sms/sent"); Cursor C=cr.query (urisms,NewString[] {"_id", "thread_id"},NULL,NULL,NULL); if(NULL! = C &&C.movetofirst ()) { Do { //Delete SMS LongThreadId = C.getlong (1); Cr.delete (Uri.parse ("content://sms/conversations/" +threadId),NULL,NULL); LOG.D ("Deletesms", "ThreadId::" +threadId); } while(C.movetonext ()); } } Catch(Exception e) {//Todo:handle ExceptionLOG.D ("Deletesms", "Exception::" +e); } } /** Delete all SMS one by one*/ Public voiddeletesms () {Try{contentresolver CR=Getcontentresolver (); //Query SMSUri urisms = Uri.parse ("Content://sms/sent"); Cursor C=cr.query (urisms,NewString[] {"_id", "thread_id"},NULL,NULL,NULL); if(NULL! = C &&C.movetofirst ()) { Do { //Delete SMS LongThreadId = C.getlong (1); Cr.delete (Uri.parse ("content://sms/conversations/" +threadId),NULL,NULL); LOG.D ("Deletesms", "ThreadId::" +threadId); } while(C.movetonext ()); } } Catch(Exception e) {//Todo:handle ExceptionLOG.D ("Deletesms", "Exception::" +e); } }
2. Increase the ability to read text messages in Androidmanifest.xml
<android:name= "Android.permission.READ_SMS"/> < android:name= "Android.permission.WRITE_SMS"/>
This article transferred from: http://dev.10086.cn/cmdn/wiki/index.php?doc-view-4919.html