2

I am making an app in which I have to get the mobile number of the GSM device and I used the following code to show to phone no in a TextView, but all in vain. Can anyone help me do this.

TelephonyManager mTelephonyMgr;
    mTelephonyMgr = (TelephonyManager)
        getSystemService(Context.TELEPHONY_SERVICE);

    String number = mTelephonyMgr.getLine1Number();

    Phoneno=(TextView)findViewById(R.id.Phoneno);


    Phoneno.setText(number);

3 Answers3

2

make sure you Requires permission READ_PHONE_STATE in manifest

Hope This will help you

Community
  • 1
  • 1
Nikunj Patel
  • 21,853
  • 23
  • 89
  • 133
  • 1
    i used the permission mentioned by you but still it is not displaying nothing –  Dec 26 '11 at 05:42
0

TelephonyManager.getLine1Number() is the only solution available till now.Actually sim does not contains info about the number .It is delivered by the network only.Also this is sim dependent .For some device it (TelephonyManager.getLine1Number()) will work.For some it may not.

shubham jain
  • 156
  • 1
  • 9
0

Check this example, it will help you to find out the issue.

Yaqub Ahmad
  • 27,569
  • 23
  • 102
  • 149