简体   繁体   中英

How to get Mobile phone Number using flutter Framework?

How can I programmatically get the phone number of the device that is running my android app using Flutter?

I know we can do this easily in android studio using this syntax :

TelephonyManager tMgr = (TelephonyManager)mAppContext.getSystemService(Context.TELEPHONY_SERVICE); 
String mPhoneNumber = tMgr.getLine1Number();

But how to do this using flutter ?

There is no cross-platform solution for that as Apple restricts its iOS Apps and prohibit the access of the phone number. The only thing you can do is write a package which only supports Android and returns the phone number. Refer to:

Programmatically get own phone number in iOS

Get the device's phone number programmatically

Edit 2019/09/03:

Some apps like Snapchat bypass Apple's restriction by sending a sms from the users phone to a server which then returns the phone number. Here is a blog post about doing this with AWS:

Capturing Mobile Phone Numbers

For Android:

Programmatically obtain the phone number of the Android phone

Create a flutter package

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