You can check Settings -> About Phone -> Status -> My Phone number in your mobile. This number is returned by getLine1Number(). If it is Unknown, then getLint1Number() will return null or "". Itseems it is Operator/SIM dependent.
Unable to get phone number in android
-
30-07-2022 - |
Question
I am trying to read the phone number in android. I've tried with these codes, but i couldn't get the number.Every one is suggesting this code only,but its not working why?
Suggestions please
Thanks for your precious time!...
MainActvity.java
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
TelephonyManager mTelephonyMgr = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
phonenumber = mTelephonyMgr.getLine1Number();
System.out.println(">>>----- Phone number-----" + phonenumber);
}
});
Manifest.xml
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
Solution
OTHER TIPS
Getting phone Number is dependent on sim .For most devices (TelephonyManager.getLine1Number()) will work.For some it may not.You replace with another sim and Check it..
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow