5

Is it possible to develop a hybrid mobile app using Phonegap / Cordova and access the device phone number for both Android and iOS?

user1995781
  • 19,085
  • 45
  • 135
  • 236

2 Answers2

8

iOS: You can retrieve the phone number using the CoreTelephony framework, you will need to add the following Entitlement: com.apple.coretelephony.Identity.get. However apple might reject your app once you upload it to the AppStore.

But if you plan to distribute using the "Enterprise Distribution" plan, you should have no problem at all, see answers by Igor Fedorchuk and Dylan here, and another elaborated answer here.

Android: Yes, you could use this plugin, or write a cordova plugin that bridges the following code:

TelephonyManager tm = (TelephonyManager)appContext.getSystemService(Context.TELEPHONY_SERVICE);
String mPhoneNumber = tm.getLine1Number();

The required permission is android.permission.READ_PHONE_STATE"

Alon Amir
  • 4,913
  • 9
  • 47
  • 86
  • 1
    In fact there are some problems with the Android code above (not all devices have the phone number stored), as explained on [this discussion](http://stackoverflow.com/questions/2480288/programmatically-obtain-the-phone-number-of-the-android-phone) – Cotta Nov 04 '15 at 12:43
1

Android:I know i am late. After Searching a lot i found this plugin which works for me perfectly... add these plugin in your project

Put these code in your index.js here

 $(document).ready(function () {
    document.addEventListener("deviceready", onDeviceReady, false);
 });

function onDeviceReady() {
    window.plugins.phonenumber.get(success, failed);

    document.addEventListener("backbutton", onBackKeyDown, false);
}

function success(phonenumber) {
    console.log("My number is " + phonenumber);
}

function failed(phonenumber) {
    console.log("Error " + phonenumber);
}

If your phone do not allow to show phonenumber then it will go to failed block.

But from That : Some vendors don't publish the phone number to the SIM card.

You can check it in Settings-> About Phone-> Status-> SIM Status.

Brett Gregson
  • 5,867
  • 3
  • 42
  • 60
ULHAS PATIL
  • 862
  • 8
  • 19