10

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 ?

kalehmann
  • 4,821
  • 6
  • 26
  • 36
Arief Wijaya
  • 827
  • 2
  • 8
  • 20

1 Answers1

6

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

For Android:

Programmatically obtain the phone number of the Android phone

Create a flutter package

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

Community
  • 1
  • 1
Bostrot
  • 5,767
  • 3
  • 37
  • 47