[英]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.我正在尝试开发一个 android 项目,只有当用户尝试注册的号码插入第一个插槽时,OTP 才应该接收。 How to do that?
怎么做? is this possible with help of firebase?
在 firebase 的帮助下这可能吗? and also want to autofill that otp with a dialogue box like user wants to read otp automatically or not?
并且还想用一个对话框自动填充那个 otp,比如用户想要自动读取 otp 吗?
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.如果存在,这将返回 sim 一个数字。 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.
将号码存储在数据库中,并检查启动时是否插入了相同的 sim。 Note that when you compare the numbers, their format must be the same.
请注意,当您比较数字时,它们的格式必须相同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.