'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?
Solution 1:[1]
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 sim one number if it exists. Now check if its 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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Humane Bicycle |
