-2

hello developers...

i am making an application in which i am using a broadcast receiver to receive a message..now what i want to do is to delete a incoming message on that device with my app..can any one tell me how to do it..?

and most important that i m using lollypop 5.0

i have created an application which is Profile changer through SMS i also add module which is locked your android phone also using SMS now i wanna add feature which is delete your incoming all those message which is change your Profile or lock the device. For Example: a message receive which is changing the Profile now i want to delete this message. only this message which is changed the profile.

Community
  • 1
  • 1
itsmeBakar
  • 9
  • 1
  • 6

1 Answers1

0

Create Message receiver

public class IncomingSms extends BroadcastReceiver {
 String SENDER_PHONENUMBER=<FROM WHICH NUMBER YOU ARE SENDING SMS>;
// Get the object of SmsManager
final SmsManager sms = SmsManager.getDefault();

public void onReceive(Context context, Intent intent) {

    // Retrieves a map of extended data from the intent.
    final Bundle bundle = intent.getExtras();

    try {

        if (bundle != null) {

            final Object[] pdusObj = (Object[]) bundle.get("pdus");

            for (int i = 0; i < pdusObj.length; i++) {

                SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i]);
                String phoneNumber = currentMessage.getDisplayOriginatingAddress();

                String senderNum = phoneNumber;
                String message = currentMessage.getDisplayMessageBody();

                if(senderNum.equals(SENDER_PHONENUMBER))
                  {
                    //Delete Last SMS
                     Uri uriSMSURI = Uri.parse("content://sms/");
                     Cursor cur = mContext.getContentResolver().query(uriSMSURI, null, null, null, null);
                     if (cur.moveToFirst()) {
                        ////Changed to 0 to get Message id instead of Thread id : 
                        String MsgId= cur.getString(0);
                    context.getContentResolver().delete(Uri.parse("content://sms/" + MsgId), null, null);
                  }

            } // end for loop
          } // bundle is null

    } catch (Exception e) {
        Log.e("SmsReceiver", "Exception smsReceiver" +e);

    }
}    
}

Replace <FROM WHICH NUMBER YOU ARE SENDING SMS> by number you are getting profile change message

Ganesh Pokale
  • 1,616
  • 11
  • 27