以下是我目前的代码:
private int deleteAllMessages(Context context){
Uri deleteUri = Uri.parse(SMS_ALL);
int count = 0;
Cursor c = context.getContentResolver().query(deleteUri, null, null, null, null);
while(c.moveToNext()){
long thread_id = c.getLong(1);
Uri thread = Uri.parse("content://sms/conversations/" + thread_id);
context.getContentResolver().delete(thread, null, null);
}
return count;
}
我想知道这句话是什么意思:
Cursor c = context.getContentResolver().query(deleteUri, null, null, null, null);
此外,如何更改它以仅删除特定邮件(已处理)而不删除收件箱中的所有邮件。
有任何帮助吗?
答案 0 :(得分:1)
我使用以下代码从我的收件箱下载短信,
private void deleteMessage()
{
Cursor c = getContentResolver().query(SMS_INBOX, null, null, null, null);
//c.moveToFirst();
while (c.moveToNext())
{
System.out.println("Inside if loop");
try
{
String address = c.getString(2);
String MobileNumber = mainmenu.getParameterData().getMobileNumber().trim();
//Log.i( LOGTAG, MobileNumber + "," + address );
Log.i( LOGTAG, c.getString(2) );
if ( address.trim().equals( MobileNumber ) )
{
String pid = c.getString(1);
String uri = "content://sms/conversations/" + pid;
getContentResolver().delete(Uri.parse(uri), null, null);
stopSelf();
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
}