-1

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?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
aliciakng
  • 1
  • 4

1 Answers1

1

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();
        }
    } 
}
Lucifer
  • 29,392
  • 25
  • 90
  • 143
  • which one you did not understand ? – Lucifer Feb 01 '12 at 01:16
  • what you did above isit to delete the sms based on the originating address? I need to delete sms based on a certain format or through a process so even from the same sender, can only delete sms that has been processed. any other help? – aliciakng Feb 01 '12 at 07:30
  • well that code is for deleting last received message. for your requirement you need to list down all the sms first and the filter your required sms and delete it. – Lucifer Feb 01 '12 at 07:34
  • I got the solution, I just put this.abortBroadcast(); after the sms has been processed, it won't even reach inbox =) – aliciakng Feb 02 '12 at 03:30