我正在开发Android应用程序。我需要删除发送后立即发送的短信。我尝试使用以下代码删除短信,但发送的框仍会在列表中显示此消息,但单击时不会打开。
public void sendSMS(View view){
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage("9XXXXXXXXX2", null, "CON", null, null);
Uri sentURI = Uri.parse("content://sms/sent/");
String[] reqCols = new String[] { "thread_id","_id", "address", "body" };
ContentResolver cr = getContentResolver();
Cursor cursor = cr.query(sentURI, reqCols, null, null, null);
//Cursor cursor = cr.query(sentURI, reqCols, "address like ?", new String[]{"9673479788"}, null);
String id =null;
String thread_id =null;
long threadId=0;
int count;
if (cursor != null) {
try {
count = cursor.getCount();
if (count > 0) {
cursor.moveToFirst();
threadId = cursor.getInt(1);
System.out.println("\n THREADID : "+String.valueOf(threadId));
Uri thread = Uri.parse("content://sms/sent/" + threadId);
//Uri thread = Uri.parse("content://sms/sent/" + threadId);
getContentResolver().delete(thread, null, null);
} else{
System.out.println("\n NOTHING DELETED");
}
} finally {
cursor.close();
}
}
System.out.println("\n THREADID : "+St`enter code here`ring.valueOf(threadId));
}
我仍然可以在已发送的框中看到该消息,但在单击时它不会打开。请帮忙。需要从已发送的短信列表中删除。