10
votes

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 ?

1
Check platform channels : flutter.io/platform-channels to call platform specific codes from flutter. - Dhiraj Sharma
ah , good idea. i'll try it. thanks. even Still Waiting for flutter release date. - Arief Wijaya

1 Answers

5
votes

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