Search packages and repositories

GitHub repositoryamorenew/Flutter-Mobile-Number-Plugin

Flutter-Mobile-Number-Plugin

Flutter Plugin to get the mobile number

Flutter-Mobile-Number-Plugin project cover
Stars
24
Forks
30
Last push (UTC)
Dec 29, 2024
Project status
Active

Original README

English project snapshot. Visit GitHub for the latest content.

mobile_number

This is a FLutter Plugin to get the device mobile number.

Note: It works for Android only because getting mobile number of sim card is not supported in iOS.
Note: If the mobile number is not pre-exist on sim card it will not return te phone number.

Installation

Link on Flutter plugins

https://pub.dev/packages/mobile_number

Note:

if you still using depecated FlutterActivty on MainActivity.java which is import of

  • import io.flutter.app.FlutterActivity;

not

  • import io.flutter.embedding.android.FlutterActivity;

then you need to add the following to your MainActivity.java

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        MobileNumberPlugin.registerWith(registrarFor("com.amorenew.mobile_number.MobileNumberPlugin()"));
    }

Usage

Check Phone Permission

await MobileNumber.hasPhonePermission

Request Phone Permission

await MobileNumber.requestPhonePermission

Listen to widget resume after Phone Permission request
      if (isPermissionGranted) {
        //Get mobile number
      } else {
        //Request Phone Permission
      }
    });
Alternative Phone Permission

permission_handler has a better implementation of device general permissions.

A simple example would be:

var status = await Permission.phone.status;
if (!status.isGranted) {
  status = await Permission.phone.request();
}

if (!status.isGranted) {
  // return or throw some error
}

return await MobileNumber.mobileNumber;

Get first sim card number
    final String mobileNumber = await MobileNumber.mobileNumber;
    return mobileNumber;
  }
Get List of sim cards for dual sim cards
    final List<SimCard> simCards = await MobileNumber.getSimCards;
    return simCards;
  }

alt text

Amr Abd El Wahab El Desouky GitHub avatar
GitHub author

Amr Abd El Wahab El Desouky ↗

Mobile Developer Android, iOS, React Native, Reactjs

LanguagesJavaDartRubyObjective-CShell

Categories

Packages published by this repository

Dependencies used

Dependency list 2 items

  • flutter{"sdk":"flutter"}
  • flutter_testDevelopment{"sdk":"flutter"}

How do I choose a repository?

Start with your use case, compare repository activity, and check the original project before adopting it.

  1. Search by repository name, owner or description, then narrow the results by topic.
  2. Compare stars, forks and recent pushes. Stars show community interest, not a guarantee of quality.
  3. Read the README, license and issues on GitHub before using a project.

Sources and maintenance

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗