1

Unable to get phone number from mobile-:

TelephonyManager tMgr = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
        String mPhoneNumber = tMgr.getLine1Number();
        Log.i("Log", "Phone no is -: "+mPhoneNumber);
        myContactNo.setText(mPhoneNumber);

I am not getting the phone number and it is empty. I have added permission in Android Manifest.

pranav shukla
  • 343
  • 4
  • 15

2 Answers2

0

Try this..

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

In AndroidManifest.xml, write the following permission:

<uses-permission android:name="android.permission.READ_PHONE_STATE"/> 

See here

Community
  • 1
  • 1
sm_
  • 3,324
  • 2
  • 12
  • 21
-1
  private String  getMobileNO()
    {
        TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        String telNumber = tm.getLine1Number();

        return telNumber;
    }

and make sure it is call through onCreate method.

Madhab Dhakal
  • 93
  • 1
  • 9