简体   繁体   中英

how to get otp when sim is inserted in 1st slot only?

I am trying to develop an android project where OTP should recive only when number which user trying to register is inserted in first slot. How to do that? is this possible with help of firebase? and also want to autofill that otp with a dialogue box like user wants to read otp automatically or not?

Permission:

<uses-permission android:name="android.permission.READ_PHONE_NUMBERS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

Use code

public String getNumber() { 
  
    if (ActivityCompat.checkSelfPermission(this, READ_SMS) == PackageManager.PERMISSION_GRANTED &&
            ActivityCompat.checkSelfPermission(this, READ_PHONE_NUMBERS) ==
                    PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,
            READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
        // Permission check
  
        // Create obj of TelephonyManager and ask for current telephone service
        TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
        String phoneNumber = telephonyManager.getLine1Number();
  
        
        return phoneNumber;
    } else {
        // Ask for permission
        requestPermission();
    return null;
    }
}

This will return the sim one number if it exists. Now check if it's equal to the number provided by the user. Store the number in the database and check whether the same sim is inserted at startup. Note that when you compare the numbers, their format must be the same.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM