Pouton Gerald
Pouton Gerald

Reputation: 1625

getting phone number from android device

Yes I am using the correct permission:

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

And here is my code:

private String getDevicePhoneNumber() {
    TelephonyManager mTelephonyMgr;
    mTelephonyMgr = (TelephonyManager)
        getSystemService(Context.TELEPHONY_SERVICE);
    return mTelephonyMgr.getLine1Number();
}

The phone is returning lambda to me: the empty string.

Does anyone know how to get this right? I need this to work for android Froyo (2.2 ) and up

Upvotes: 0

Views: 396

Answers (1)

Dory Zidon
Dory Zidon

Reputation: 10719

It's a problem indeed. There is no one solution to that will always work. It is not stored on all SIM cards nor is it accessible always from the carrier network.

Physical address verification might be even require in some countries.

The assignment of a phone number assignment happens on the network - and can be changed without changing the SIM card or device (e.g. this is how porting is supported to work when moving from one carrier to another..).

you best bet is to ask the user, as strange as that might sound..

Upvotes: 2

Related Questions