3 回答

TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超8個(gè)贊
將應(yīng)用程序設(shè)置為默認(rèn)應(yīng)用程序,請參見此。刪除之前,請檢查您的應(yīng)用是否為默認(rèn)短信應(yīng)用。使用電話類提供的URI而不是硬編碼。
public void deleteSMS(Context context,int position)
{
Uri deleteUri = Uri.parse(Telephony.Sms.CONTENT_URI);
int count = 0;
Cursor c = context.getContentResolver().query(deleteUri, new String[]{BaseColumns._ID}, null,
null, null); // only query _ID and not everything
try {
while (c.moveToNext()) {
// Delete the SMS
String pid = c.getString(Telephony.Sms._ID); // Get _id;
String uri = Telephony.Sms.CONTENT_URI.buildUpon().appendPath(pid)
count = context.getContentResolver().delete(uri,
null, null);
}
} catch (Exception e) {
}finally{
if(c!=null) c.close() // don't forget to close the cursor
}
}
它刪除所有(收件箱,發(fā)件箱,草稿)短信。
- 3 回答
- 0 關(guān)注
- 648 瀏覽
添加回答
舉報(bào)