0

I found out that this code shared by some users doesn't work in my project. Has anyone a better solution ?

TelephonyManager tMgr = (TelephonyManager)mAppContext.getSystemService(Context.TELEPHONY_SERVICE);
String mPhoneNumber = tMgr.getLine1Number();

I'm getting an error on the getLine1Number() and on the mAppContext

Yksh
  • 3,276
  • 10
  • 56
  • 101
Luis Violas
  • 75
  • 2
  • 9
  • 2
    Possible duplicate of [Programmatically obtain the phone number of the Android phone](http://stackoverflow.com/questions/2480288/programmatically-obtain-the-phone-number-of-the-android-phone) – Bajirao Shinde Mar 16 '16 at 10:54
  • What error are you getting? – stefana Mar 16 '16 at 11:00
  • "mAppContext does not exist in the current context" and "TelephonyManager does not contain a defenition for GetLine1Number()" – Luis Violas Mar 16 '16 at 11:04
  • @LuisViolas : Your code is in native Android (Java). You must use Xamarin.Android (C#). Try this : http://stackoverflow.com/a/36034077/3891036 – Yksh Mar 16 '16 at 11:22

1 Answers1

0

Did you add <uses-permission android:name="android.permission.READ_PHONE_STATE"/> to manifest?

It's not really perfect, but the only way (at least to my knowledge). Broader discussion is here Programmatically obtain the phone number of the Android phone

Community
  • 1
  • 1
Jakoss
  • 4,647
  • 2
  • 26
  • 40