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 ?
We can get current device information from within the Flutter application by using the device_info_plus package. Which is supports all kinds of platforms, including Android, iOS, macOS, web, Linux, and Windows.
What is Flutter? Flutter is Google's open-source technology for creating mobile, desktop, and web apps with a single codebase. Unlike other popular solutions, Flutter is not a framework or library; it's a complete SDK – software development kit.
Create a New Flutter ProjectStep 1: Open the Android Studio IDE and select Start a new Flutter project. Step 2: Select the Flutter Application as the project type. Then click Next. Step 3: Verify the Flutter SDK path specifies the SDK's location (select Install SDK… if the text field is blank).
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With