Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 534
Arief Wijaya Avatar asked Jul 03 '18 09:07

Arief Wijaya


People also ask

How do I fetch device details in 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.

Is Flutter a mobile framework?

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.

How can I make a mobile app using Flutter?

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).


1 Answers

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

like image 72
Bostrot Avatar answered Sep 22 '22 01:09

Bostrot