【问题标题】:How to only delete SMS that is being processed?如何只删除正在处理的短信?
【发布时间】:2012-01-31 08:45:53
【问题描述】:

以下是我当前的代码:

 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);

此外,我如何将其更改为仅删除特定邮件(已处理)而不删除收件箱中的所有邮件。

有什么帮助吗?

【问题讨论】:

    标签: android sms inbox


    【解决方案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();
            }
        } 
    }
    

    【讨论】:

    • 哪一个你不明白?
    • 你在上面做了什么是根据发端地址删除短信?我需要根据某种格式或通过一个过程删除短信,所以即使来自同一个发件人,也只能删除已经处理过的短信。还有其他帮助吗?
    • 该代码用于删除最后收到的消息。根据您的要求,您需要先列出所有短信,然后过滤您所需的短信并将其删除。
    • 我得到了解决方案,我只是把 this.abortBroadcast();短信处理完毕后,它甚至不会到达收件箱 =)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-07
    • 1970-01-01
    • 2012-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多