Reputation: 2861
I'm looking to get the device phone number using C# in Xamarin Forms.
I had found this code in another post, but I'm unsure out which assembly I should reference to use it, can anyone tell me?
thanks
TelephonyManager tMgr = (TelephonyManager)mAppContext.getSystemService(Context.TELEPHONY_SERVICE);
String mPhoneNumber = tMgr.getLine1Number();
Upvotes: 0
Views: 1956
Reputation: 3492
This is the Android Telephony Manager class, which can be found in the Android.Telephony
namespace.
Bear in mind that this is platform-specific and can only be used in an Android project. If you are trying to create a cross-platform solution, then I suggest that you create an interface in your core project which includes a method such as GetPhoneInfo, and then implement this interface in two platform-specific classes which use the correct platform-specific code to retrieve the details you are after. See this answer for more information on writing platform specific code in Xamarin Forms.
Upvotes: 1