gpt4 book ai didi

java - 如何删除Android中特定联系人号码的所有短信

转载 作者:行者123 更新时间:2023-12-02 07:47:09 25 4
gpt4 key购买 nike

我有以下代码可以删除所有短信对话,

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;

但我想删除特定联系号码的短信,该怎么办?

最佳答案

您可以使用删除特定号码的所有短信,

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();
}

关于java - 如何删除Android中特定联系人号码的所有短信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10664873/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com