How to check user entered own phone number in EditText?

前端 未结 5 658
醉酒成梦
醉酒成梦 2021-02-08 10:26

Mobile number will be entered in an edittext by user on registration page in my Android application. How can I check that user entered his/her mobile number not other\'s ?

5条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-08 10:52

    Its not guaranteed that tMgr.getLine1Number(); will always return your SIM card's number. Because it depends on the availability of number in SIM card. Like in my case, my Tre-Sweden SIM card doesn't contain my phone number.

    But if you put the SIM card into an old SonyEricsson or Nokia phone, then you would get an option to edit this number (on SIM). Once its done, the android device will recognize the number and will show you.

    Besides, if you do get your phone number through the code, then the best way to compare two numbers is:

    boolean isSame = PhoneNumberUtils.compare(num1, num2);
    

    Alternatively, you may implement some sort of pin-code verification logic (like Viber, WhatsApp or other application does) in which you ask the user to enter their phone number during registration. Later, that phone number is sent to the server and a pin-code is generated against that number which is sent to the user via SMS. Finally, the user has to enter that pin-code (received in SMS) to complete the registration.

    Or

    Simply send an SMS from user's device (with a consent) to your server/device and get to know their phone number.

提交回复
热议问题