2012-03-08 67 views
0

我目前正試圖從android短信息表中刪除短信。 我用它來刪除短信,但有錯誤。 這是正確的語法嗎? messageID是要刪除的消息的ID。在android中從SMStable中刪除短信

Uri uriSMSURI = Uri.parse("content://sms/inbox/" + messageID); 

getContentResolver().delete(uriSMSURI, null, null); 
+0

在AndroidManifest.xml檢查權限的文件? – 2012-03-08 11:07:59

+0

也,錯誤說java.lang.IllegalArgumentException:未知的URL – marchemike 2012-03-08 11:21:26

回答

4

delete一個用於短信,您必須在AndroidManifest.xml中添加這些權限:

<uses-permission android:name="android.permission.WRITE_SMS"> </ uses-permission> 
<uses-permission android:name="android.permission.READ_SMS"> </ uses-permission> 

URI的讀取和刪除短信:

//Available Uri string 
    String strUriInbox = "content://sms/inbox";//SMS_INBOX:1 
    String strUriFailed = "content://sms/failed";//SMS_FAILED:2 
    String strUriQueued = "content://sms/queued";//SMS_QUEUED:3 
    String strUriSent = "content://sms/sent";//SMS_SENT:4 
    String strUriDraft = "content://sms/draft";//SMS_DRAFT:5 
    String strUriOutbox = "content://sms/outbox";//SMS_OUTBOX:6 
    String strUriUndelivered = "content://sms/undelivered";//SMS_UNDELIVERED 
    String strUriAll = "content://sms/all";//SMS_ALL 
    String strUriConversations = "content://sms/conversations";//you can delete one conversation by thread_id 
    String strUriAll = "content://sms"//you can delete one message by _id 
+0

我已經添加了這些權限,但它仍然沒有好處。 – marchemike 2012-03-08 11:16:32

+2

我只需要更改內容:// sms/inbox/with content:// sms / – marchemike 2012-03-08 14:03:12