How to only delete SMS that is being processed?

1.1k Views Asked by At

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?

1

There are 1 best solutions below

4
On BEST ANSWER

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