如何监听短信会话(对话)的删除
如题
[解决办法]
/*用户使用系统自带的短信程序发送短信,程序会把短信通过ContentProvider保存进数据库,并且发出一个数据变化通知,只要使用ContentObserver对数据变化进行监听,在用户发送短信时,就会被ContentObserver窃听到:注册监听:getContentResolver().registerContentObserver(Uri.parse("content://sms"), true, new SmsObserver(new Handler()));监听类:*/private final class SmsObserver extends ContentObserver{ public SmsObserver(Handler handler) { super(handler); } public void onChange(boolean selfChange) {//查询发送箱中的短信(处于正在发送状态的短信放在发送箱) Cursor cursor = getContentResolver().query(Uri.parse("content://sms/outbox"),null, null, null, null); while(cursor.moveToNext()){ StringBuilder sb = new StringBuilder(); sb.append("_id=").append(cursor.getInt(cursor.getColumnIndex("_id"))); sb.append(",address=").append(cursor.getString(cursor.getColumnIndex("address"))); sb.append(";body=").append(cursor.getString(cursor.getColumnIndex("body"))); sb.append(";time=").append(cursor.getLong(cursor.getColumnIndex("date"))); Log.i("ReceiveSendSMS", sb.toString()); } } }
[解决办法]
getContentResolver().delete(Uri.parse("content://sms/conversations/" + groupId), null, null);