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 - |
سؤال
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"/>
المحلول
نصائح أخرى
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..
لا تنتمي إلى StackOverflow