简体   繁体   中英

Foolproof way to get Android User's Personal Phone Number?

I currently use this:

TelephonyManager telephonyManager = 
(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);

String phoneNumber = telephonyManager.getLine1Number();

Which works like 85% of the time. But on some phones it returns nothing. I believe this is due to differences in Sim cards.

Is there somewhere else on the Android platform to gain this information reliably?

Thanks

There isn't one. As far as I know, getLineNumber() returns the Number that is shown in the About Phone screen but it doesn't always work. The api for getLineNUmber() even says this, it returns null when the phone number isn't available.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM