无法以编程方式删除的短信 [英] Unable to delete SMS programmatically
本文介绍了无法以编程方式删除的短信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我曾尝试在删除所有或部分消息从SMS,包括但不限变化,以线程ID,ID,where子句,等等。
Android清单反映了读取和写入权限。
我试图对短信内容的变化,从收件箱等。
似乎没有任何要删除的记录。
下面是最后一次迭代:
。 光标C = getApplicationContext()getContentResolver()查询(Uri.parse(内容://短信/),NULL,NULL,NULL,NULL);
尝试{
而(c.moveToNext()){
INT标识= c.getInt(0);
串PID = c.getString(0);
//字符串URI =内容://短信/通话/+的threadId;
字符串strUriAll =内容://短信/+ PID; // SMS_ALL
Log.d(URI是strUriAll);
。getApplicationContext()getContentResolver()删除(Uri.parse(strUriAll),NULL,NULL);
// getApplicationContext()getContentResolver()删除(Uri.parse(strUriAll),NULL,NULL);
} }赶上(例外五){
Log.e(this.toString(),错误删除短信,E);
} {最后
c.close();
}
解决方案
Android 4.4的奇巧推出的短信处理更改那里现在只有默认的短信应用允许SMS数据库的写入权限 - 所有其他应用默默尝试写入时失败。 p>
I have tried variations on deleting all or some messages from the SMS, including but not limited to thread id, id, where clause, etc. Android manifest reflects read and write permissions. I tried with variations on the SMS content, from inbox etc. Nothing seems to delete the record.
Here is the last iteration:
Cursor c = getApplicationContext().getContentResolver().query(Uri.parse("content://sms/"), null, null, null,null);
try {
while (c.moveToNext()) {
int Id = c.getInt(0);
String pid = c.getString(0);
// String uri = "content://sms/conversations/" + threadId;
String strUriAll = "content://sms/" + pid;//SMS_ALL
Log.d("URI is ", strUriAll);
getApplicationContext().getContentResolver().delete(Uri.parse(strUriAll), null, null);
// getApplicationContext().getContentResolver().delete(Uri.parse(strUriAll), null, null);
}
}catch(Exception e){
Log.e(this.toString(),"Error deleting sms",e);
}finally {
c.close();
}
解决方案
Android 4.4 Kitkat introduced changes in SMS handling where now only the default SMS app is allowed write access to the SMS database - all other apps silently fail when attempting to write.
这篇关于无法以编程方式删除的短信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文