0

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();
}
Jacob Ras
  • 5,974
  • 1
  • 28
  • 26
Makam
  • 11
  • 2

2 Answers2

4

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

Ilya Saunkin
  • 18,934
  • 9
  • 36
  • 50
1

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" />
Jacob Ras
  • 5,974
  • 1
  • 28
  • 26