开发者

Delete SMS after displaying

开发者 https://www.devze.com 2023-01-17 04:55 出处:网络
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 nat

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?

T开发者_JS百科hanks In Advance, Perumal


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

精彩评论

暂无评论...
验证码 换一张
取 消