一旦用戶閱讀,我想從收件箱中刪除短信。這個怎麼做?從收件箱中刪除短信
編輯:
公共類SmsReceiver擴展廣播接收器{
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String address = null;
if(bundle!=null) {
String info = " ";
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for (int i=0; i<msgs.length; i++) {
msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
address=msgs[i].getDisplayOriginatingAddress();
info += msgs[i].getMessageBody().toString();
}
/*String str=bundle.getString("state");
Log.v("State",str);*/
if((PhoneNumberUtils.isWellFormedSmsAddress(address))){ //set ! and address length
//abortBroadcast();
Log.v("phone num","wellformed");
Uri deleteUri = Uri.parse("content://sms");
Cursor c = context.getContentResolver().query(deleteUri, null, null,
null, null);
while (c.moveToNext()) {
try {
// Delete the SMS
String pid = c.getString(0); // Get id;
String uri = "content://sms/conversations/" + pid;
context.getContentResolver().delete(Uri.parse(uri),
null, null);
} catch (Exception e) {
Log.v("exception","occurred");
}
}
}
}
}
}
什麼是錯的代碼?短信沒有被清除
將這個代碼刪除所有收件箱消息 – Erum 2015-02-11 05:04:56
無法在Android 4.3版上工作 – NarendraJi 2015-04-14 12:22:55
這項工作將在5.0版本中完成嗎?使用相同的代碼將空遊標返回。 – Akshat 2015-04-28 14:11:03