0

I want to know, how we get mobile number of same device on which android application is running.

I follow this link https://www.youtube.com/watch?v=9A_bHH9blZE.

In which I use

uses-permission android:name="android.permission.READ_PHONE_STATE" in <> tag

in manifeast.xml file of application.

And Use TelephonyManager class to get number as

TalaphonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

String number = tm.getLine1Number();

in onCreate method of MyActivity.java file.

BUT I get blank in number field.

Please help me to solve this issue.

  • are you actually dumping the value of `number` anywhere? like to logcat or setting it to a textview? how do you know the number isn't being pulled properly? – burmat Sep 19 '14 at 16:33

1 Answers1

0

Looking at the code which you posted there seems to be nothing wrong and this behaviour is mentioned in api for getLine1Number()

Returns the phone number string for line 1, for example, the MSISDN for a GSM phone. Return null if it is unavailable.

sol4me
  • 15,233
  • 5
  • 34
  • 34