How to get Android phone number?

This is an extension for the question here . Now i quote CommonsWare

There is no reliable way to get the mobile number of devices programmatically. The only remaining option that I can think of is to force the user to enter a phone number.

My question is how to check if the phone number entered by the user is correctly specified and any other features that I cannot think about right now:

  • The number entered by the user refers to the same device onto which the application was downloaded.
  • The user did not make any typographical errors when entering the number
  • The user did not enter a local call code, for example, leading 0

I have spent enough time on StackOverflow and the Internet, and this is not a duplicate question.

I will be grateful for any help, tips or suggestions.

+6
source share
3 answers

1. The number entered by the user refers to the same device onto which the application was downloaded.

Again this is something impossible to test, otherwise the Tricky way mentioned by @neteinstein


2. The user did not make any typographical errors when entering the number

3. The user did not enter the local call code, for example, the leader 0

I think that you still do not know about this library used for parsing / formatting / checking phone numbers for all countries / regions of the world.

Using this, you can achieve two other solutions. I think.


Link: http://code.google.com/p/libphonenumber/

+1
source

If you are ready to spend some money on a user, you can send an SMS message to yourself (the number entered by the user) and check if it has arrived.

If so, the number is correct. If not ... either you do not have a network or the number is incorrect.

I don’t even think that the phone has visibility of the number, in accordance with my experience with mobile operators, only on their side they have this visibility.

+1
source

Although I do not know about nr1, I think that you can solve the problems of nr 2 and 3 quite easily by analyzing the number, while String. This way, you can easily check which characters it contains and at what positions these characters are included. Hope this helps.

Congratulated Wottah

0
source

Source: https://habr.com/ru/post/914987/


All Articles