I’m writing an app for Android (2.1+), and I’d like to use the telephone number of the current phone. Lots of googling brought me the following:
String number=(TelephonyManager)getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE).getLine1Number();
That along with permission: READ_PHONE_STATE.
My problem however is that it returns null. While searching, I noticed this question has been asked many times before and nearly in all of those questions it is said that the number simply isn’t always available.
While testing I found that on my very own phone it gives me null. BUT another app (for example, WhatsApp) was able to recognize my phone number).
So then I wonder, how did they do it?
Well, I came up with another method to retrieve the telephone number (which in my case really is a absolute must-have).
That’s the basic idea.