简体   繁体   English

仅将 sim 卡插入第一个插槽时如何获取 otp?

[英]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.

相关问题 Airflow:如何获取数据插入BigQuery表的当前日期? - Airflow: How to get the current date of when data is inserted into a BigQuery table? 部署第一代云函数时获取 function.js 不存在错误 - Getting function.js does not exist error when deploying 1st gen cloud function 如何删除超过 7 天的文件但在 Amazon S3 中保留每月 1 号的最后 6 个文件? - How to delete files older than 7 days but keep last 6 files of 1st of every month in Amazon S3? 如何通过 AWS S3 删除 CSV 文件的第一行 - How can I remove the 1st line of a CSV file which is in AWS S3 through flutter 如何从 firebase 获取 OTP 自动填充到 otpController.text - flutter how to get OTP autofill in to otpController.text from firebase Slot Filling -- 参数为空时只提示页面参数填写 - Slot Filling -- Only prompting page parameter fulfillment when parameter is empty Amazon Lex:如何在 Lambda function (Python) 中获取插槽的 Elicitation 值? - Amazon Lex : How to get Elicitation value of a slot in Lambda function (Python)? 如何获取插入文档的 ID firebase-admin - How can I get the id of a inserted document firebase-admin Aws Glue Crawler 在第一次爬网后没有更新表 - Aws Glue Crawler is not updating the table after 1st crawl Firebase 电话认证只发送 OTP 用于测试电话号码 - Firebase Phone authentication only sending OTP For Testing Phone Numbers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM