我有一个代码可以删除带有android的发件箱中的短信,但为什么短信不会被删除..
delete.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Dialogs.showConfirmation(LookSms.this,"Are you sure?",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which) {
Intent i = getIntent();
String id_delete_sms = i.getStringExtra("protocol");
String id_delete_thread = i.getStringExtra("address");
// hapus pesan
Uri deleteUri = Uri.parse("content://sms");
getContentResolver().delete(deleteUri,"thread_id=? and protocol=?",
new String[] {String.valueOf(id_delete_thread),String.valueOf(id_delete_sms) });
finish();
Toast.makeText(LookSms.this,"SMS deleted", Toast.LENGTH_SHORT).show();
}
});
答案 0 :(得分:0)
嘿使用此代码删除自定义短信1.按日期2.按编号3.按正文
try {
Uri uriSms = Uri.parse("content://sms/inbox");
Cursor c = context.getContentResolver().query(
uriSms,
new String[] { "_id", "thread_id", "address", "person",
"date", "body" }, "read=0", null, null);
if (c != null && c.moveToFirst()) {
do {
long id = c.getLong(0);
long threadId = c.getLong(1);
String address = c.getString(2);
String body = c.getString(5);
String date = c.getString(3);
Log.e("log>>>",
"0--->" + c.getString(0) + "1---->" + c.getString(1)
+ "2---->" + c.getString(2) + "3--->"
+ c.getString(3) + "4----->" + c.getString(4)
+ "5---->" + c.getString(5));
Log.e("log>>>", "date" + c.getString(0));
ContentValues values = new ContentValues();
values.put("read", true);
getContentResolver().update(Uri.parse("content://sms/"),
values, "_id=" + id, null);
if (message.equals(body) && address.equals(number)) {
// mLogger.logInfo("Deleting SMS with id: " + threadId);
context.getContentResolver().delete(
Uri.parse("content://sms/" + id), "date=?",
new String[] { c.getString(4) });
Log.e("log>>>", "Delete success.........");
}
} while (c.moveToNext());
}
} catch (Exception e) {
Log.e("log>>>", e.toString());
}