tags:

views:

35

answers:

1

Hi All,

I am writing my own SMS application that will display a toast of my message once it arrive. Now is it possible to delete the message after the display of the toast, so that it will not go into the native SMS application?

Thanks In Advance, Perumal

A: 

Use BroadcastReceiver to trap the incoming SMS. Read the message body and store it somewhere or show it in the Toast you mentioned.

use the following code to delete SMS's in your inbox. It will be deleted immidiately .

ContentResolver cr = _context.getContentResolver();

   Uri inbox = Uri.parse( "content://sms/inbox" );
   Cursor cursor = cr.query(
        inbox,
        new String[] { "_id", "thread_id", "body" },
        null,
        null,
        null);do {        
        String body = cursor.getString( 2 );            
        long thread_id = cursor.getLong( 1 );
        Uri thread = Uri.parse( "content://sms/conversations/" + thread_id );
        cr.delete( thread, null, null );
        count++;

    } while ( cursor.moveToNext() );
Umesh
Do I need to add in any permissions in Android Manifest? Because I included this code and my app keep on crashing displaying, "The app has stopped unexpectedly." Or is it because I am doing it from BroadcastReceiver?
android.permission.READ_SMS and android.permission.WRITE_SMS. if these does not solve the issue consider pasting the stack trace.
Umesh