How to get the mobile number of your own device in Android?

I want to programmatically display the mobile number of the device. My code: -

TelephonyManager telephonyManager = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE); String strMobileNumber = telephonyManager.getLine1Number(); 

and I set the READ_PHONE_STATE permission in the AndroidManifest.xml file. This works on the emulator, but on the device with the eclair version itself, it returns an empty string. Is there any other way to get mobile connection?

+3
source share
1 answer

There is no reliable way to โ€œhone a deviceโ€™s mobile number programmatically," AFAIK. getLine1Number() reports the number provided by the SIM card for GSM phones, and the mobile phone number should not be on the SIM card.

+4
source

Source: https://habr.com/ru/post/914988/


All Articles