¿Cómo eliminar solo los SMS que se están procesando?

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.

¿Alguna ayuda?

preguntado el 31 de enero de 12 a las 08:01

1 Respuestas

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

Respondido el 31 de enero de 12 a las 12:01

which one you did not understand ? - Lucifer

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

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

I got the solution, I just put this.abortBroadcast(); after the sms has been processed, it won't even reach inbox =) - aliciakng

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.