As Pat said, although there is an API for accessing the “own number” slot on the SIM card, this slot is rarely populated in my experience.
A common strategy for obtaining a phone number for a connected application is to send an SMS as part of the verification process. Or:
Programmatically send SMS from your phone to your server (there are a lot of good gateway providers for SMS gateways) SMS will arrive on your server “from” the phone number (or SIM card to be more correct). Of course, the SMS must contain some token so that the server can associate it with this session / user. This has the advantage that you do not need the user to enter their own phone number (which is weak with little difficulty, given that few people understand how to format numbers in E.164 format). One of the drawbacks is that the process can cost you user money (one SMS message).
Ask the user to enter their phone number (website or handset) and connect to your server by passing that phone number. Pick up the phone, then wait for the SMS to be sent from your server. If this SMS really arrives, you have confirmed the phone number entered by him as correct and valid. The obvious drawback is that it depends on how the user enters their number correctly - again, given the many ways to write phone numbers around the world, it is not as trivial as it seems to normalize numbers to E.164 ....
Alas, none of these methods is bulletproof, especially because SMS is an unrelated transport. Depending on the load of the GSM network, the load of your gateway provider, the moon phase and the direction of the window blowing SMS can take from a month to a month (yes, I have experience of the latter). The average delivery time is often in seconds, but you need to play with a timeout operation and you may have to configure it on the geographic and GSM networks. [And no, don't rely on delivery reports - even more unreliable than SMS delivery)
KevinD
source share