package com.ttiglobal.inttilectgpchat.service;


import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;

import java.util.Objects;

public class IncomingSMSReceiver extends BroadcastReceiver {

    public void onReceive(Context context, Intent intent) {
        final Bundle bundle = intent.getExtras();
        try {
            if (bundle != null) {
                final Object[] pdusObj = (Object[]) bundle.get("pdus");
                String phoneNumber = null;
                String message = null;
                for (Object aPdusObj : Objects.requireNonNull(pdusObj)) {
                    SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) aPdusObj);
                    phoneNumber = currentMessage.getDisplayOriginatingAddress();
                    message = currentMessage.getDisplayMessageBody();
                }

                if (Objects.requireNonNull(phoneNumber).trim().equalsIgnoreCase("HP-SUZSTR")) {
                    String otp = message.toLowerCase().substring(message.toLowerCase().indexOf("suzuki star app is "));
                    otp = otp.replace("suzuki star app is ", "");
                    otp = otp.substring(0, 4);
                    try {
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}