Makam
Makam

Reputation: 11

Unable to fetch Mobile number on Android 2.2

I have used the standard code below to fetch the mobile number on my ANDROID 2.2 GSM device, BUT I ALWAYS GET AN EMPTY STRING. Is this feature supported on 2.2? Any suggestion as to how I can fetch the mobile number on Android 2.2 device.

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

Upvotes: 0

Views: 372

Answers (2)

Ilya Saunkin
Ilya Saunkin

Reputation: 19820

Go to Settings -> About phone -> Status -> see at My Phone Number field. If it says "Unknown" then it's not your issue, it's just the fact that some carriers don't pack the SIM cards with own number. On some devices user can edit own number, but it's not always supported by the firmware.

Read here

Upvotes: 4

Jacob Ras
Jacob Ras

Reputation: 5969

That should work, but make sure you're requesting the READ_PHONE_STATE permission in your Manifest:

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

Upvotes: 1

Related Questions