删除短信的Android 1.5 [英] Delete SMS in Android 1.5
本文介绍了删除短信的Android 1.5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有太多问题,没有答案工作在我的应用程序:(
我需要从一个接收器中删除的短信,即使用户能看到它,但它必须以编程删除。
我该怎么办呢?
我所使用的最适合的是以下内容,但它不工作:(
context.getContentResolver()。删除(
deleteUri,
地址=?和日期=?,
新的String [] {msg.getOriginatingAddress()
将String.valueOf(msg.getTimestampMillis())});
解决方案
我的重构code,我发现下一个解决方案的工作原理后:
私人诠释DeleteMessage可以(上下文的背景下,SmsMessage味精){
乌里deleteUri = Uri.parse(内容:// SMS);
诠释计数= 0;
光标C = context.getContentResolver()查询(deleteUri,NULL,NULL,
NULL,NULL);
而(c.moveToNext()){
尝试 {
//删除短信
串的pid = c.getString(0); //获取ID;
字符串URI =内容://短信/+ PID;
数= context.getContentResolver()。删除(Uri.parse(URI),
NULL,NULL);
}赶上(例外五){
}
}
返回计数;
}
谢谢大家的帮助!
PS如果有人这样code是有用的 - 记住,赶上(例外)不好
There are many questions about it, no answers are working in my application :(
I need to remove SMS from a receiver, even if the user can see it, but it must be removed programmatically.
How can I do it?
The most suitable I have used was the following, but it doesn't work :(
context.getContentResolver().delete(
deleteUri,
"address=? and date=?",
new String[] { msg.getOriginatingAddress(),
String.valueOf(msg.getTimestampMillis()) });
解决方案
After refactoring my code I found that next solution works:
private int deleteMessage(Context context, SmsMessage msg) {
Uri deleteUri = Uri.parse("content://sms");
int count = 0;
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/" + pid;
count = context.getContentResolver().delete(Uri.parse(uri),
null, null);
} catch (Exception e) {
}
}
return count;
}
Thanks everyone for help!
ps if this code is useful for some one - remember that catch(Exception) is not good.
这篇关于删除短信的Android 1.5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文