我有以下代码删除所有短信对话
Uri inboxUri = Uri.parse("content://sms/conversations");
int count = 0;
Cursor c = context.getContentResolver().query(inboxUri , null, null, null, null);
while (c.moveToNext()) {
try {
// Delete the SMS
String pid = c.getString(0); // Get id;
String uri = "content://sms/" + pid;
count = context.getContentResolver().delete(Uri.parse(uri),
null, null);
} catch (Exception e) {
}
}
return count;
但我想删除特定联系电话的短信,怎么办?
答案 0 :(得分:2)
您可以使用
删除特定号码的所有短信private void removeMessage(Context context, String fromAddress) {
Uri uriSMS = Uri.parse("content://sms/inbox");
Cursor cursor = context.getContentResolver().query(uriSMS, null,
null, null, null);
cursor.moveToFirst();
if(cursor.getCount() > 0){
int ThreadId = cursor.getInt(1);
Log.d("Thread Id", ThreadId+" id - "+cursor.getInt(0));
Log.d("contact number", cursor.getString(2));
Log.d("column name", cursor.getColumnName(2));
context.getContentResolver().delete(Uri.
parse("content://sms/conversations/"+ThreadId), "address=?",
new String[]{fromAddress});
Log.d("Message Thread Deleted", fromAddress);
}
cursor.close();
}