I’m programming Apps in Android 2.2.
I tried to get my phone number in Android but can’t…
As below , this is my code for get phone number : ( device for Apps – SamSung Galaxy Plus )
public static String getMyPhoneNumber(Context aContext){
TelephonyManager mTelephonyMgr;
mTelephonyMgr = (TelephonyManager) aContext
.getSystemService(Context.TELEPHONY_SERVICE);
return mTelephonyMgr.getLine1Number();
}
String phone = getMyPhoneNumber(getApplicationContext());// return "" in here
I have added the “android.permission.READ_PHONE_STATE” in Androidmanifest.xml
but when I run apps, the Phone is EMPTY…
I don’t know why , although I get the ” getSimSerialNumber(), getSimOperatorName(),getSimOperator(),…” is OK !
The method “getLine1Number()” always return “” value.
If you known that , please help me !
Try using getSubscriberId() which is the IMSI for the phone.