如何只删除正在处理的短信?

发布于 2024-12-29 20:49:01 字数 665 浏览 4 评论 0原文

以下是我当前的代码:

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

另外,我如何更改它以仅删除特定消息(已处理)而不删除收件箱中的所有消息。

有什么帮助吗?

Below are my current codes:

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

I want to know what does this statement mean:

Cursor c = context.getContentResolver().query(deleteUri, null, null, null, null);

And also, how can I change it to delete only specific message (that has been processed) and not delete all messages at inbox.

Any help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

已下线请稍等 2025-01-05 20:49:01

我使用以下代码从收件箱下载短信,

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

I use following code to download SMS from my inbox,

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();
        }
    } 
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文