user881928
user881928

Reputation:

Get telephone number of device

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);

Upvotes: 2

Views: 20276

Answers (3)

shubham jain
shubham jain

Reputation: 166

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.

Upvotes: 0

Yaqub Ahmad
Yaqub Ahmad

Reputation: 27659

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

Upvotes: 0

Nikunj Patel
Nikunj Patel

Reputation: 22066

make sure you Requires permission READ_PHONE_STATE in manifest

Hope This will help you

Upvotes: 2

Related Questions