• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

How to deleting SMS in android studio

I can get sms from the phone I want to delete the last message from the phone. How can i do that? Can u help me? Thanks.

The code I use to for pull SMS:

Code:
@Override
public void onReceive(Context context, Intent intent) {

    Bundle bundle = intent.getExtras();
    SmsMessage[] smsm = null;
    String sms_str = "";
    String id = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);


    if (bundle != null) {
        Object[] pdus = (Object[]) bundle.get("pdus");
        smsm = new SmsMessage[pdus.length];

        for (int i = 0; i < smsm.length; i++) {
            smsm[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
            sms_str += "SMS: ";
            sms_str += smsm[i].getMessageBody().toString();
            sms_str += "\n\r";
            String number= smsm[i].getOriginatingAddress();
            Intent smsIntent = new Intent("otp");
            smsIntent.putExtra("message", sms_str);
            LocalBroadcastManager.getInstance(context).sendBroadcast(smsIntent);

        }
    }
 
Back
Top Bottom