Dave Kapildev
Dave Kapildev

Reputation: 521

Fetch phone number for Android, IOS and Windows Phone

I am working on a Xamarin forms project and want to fetch user's phone number from device.

Please anyone can guide me how can I fetch phone number for Android, IOS and Windows Phone

Please suggest if any nuget package or third party library is available.

Thanks in advance

Upvotes: 1

Views: 2630

Answers (3)

MayankD
MayankD

Reputation: 91

There is already plugin available for the same, You can use ContactsPlugin for Fetch Contact Number in Xamarin Forms,

Please check below link for the same. https://github.com/jamesmontemagno/ContactsPlugin

Thanks

Upvotes: 0

Nico Zhu
Nico Zhu

Reputation: 32775

how can I fetch phone number for Android, IOS and Windows Phone.

For Windows Phone, you could get SIM MSISDN & IMSI number in Windows Phone Application. Please notice that you should manually edit your application Package.appxmanifest as follows:

<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" 
    xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
    xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
    xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
    IgnorableNamespaces="uap mp rescap">

......

<Capabilities>
    <rescap:Capability Name="cellularDeviceIdentity" />
</Capabilities>

You could use MobileBroadbandModem class to get all CurrentDeviceInformation. For more you could refer this case reply. Note you could not use code where in above case reply directly. You need to create DependencyService for UWP project in your Xamarin.Forms library.

For IOS, the short answer is "no way". You have to ask the user to enter it manually. There are private APIs to access the user's phone number, but then Apple will reject your app.

Upvotes: 0

Sayo Komolafe
Sayo Komolafe

Reputation: 998

Try this

TelephonyManager mTelephonyMgr;

   mTelephonyMgr = (TelephonyManager)GetSystemService(TelephonyService);

   var Number = mTelephonyMgr.Line1Number;

Source: Xamarin Forum

Make sure to add the ReadPhoneState permission in your manifest

Upvotes: 1

Related Questions