-1

This code is not working...It giving null...

TelephonyManager tMgr = (TelephonyManager)HomeActivity.this.getSystemService(Context.TELEPHONY_SERVICE);
String mPhoneNumber = tMgr.getLine1Number();

Log.e("Mobile No. :",""+mPhoneNumber);
Toast.makeText(getApplicationContext(),mPhoneNumber,Toast.LENGTH_SHORT).show();
HDJEMAI
  • 9,436
  • 46
  • 67
  • 93
Vishal Vaishnav
  • 3,346
  • 3
  • 26
  • 57

3 Answers3

1

Here is the code for it:

TelephonyManager telemamanger = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String getSimSerialNumber = telemamanger.getSimSerialNumber();
String getSimNumber = telemamanger.getLine1Number();

and you also have to add "READ_PHONE_STATE" permission in Androidmanifest.xml file.

and if you are testing the app on higher OS device then you also have to ask for the permission externally.

hope this will help you. :)

Hardik Maru
  • 661
  • 5
  • 8
0

Check in Phone--> Settings --> About --> Phone identity If you are able to view the number then you will get phone number otherwise won't able to get number

Preet
  • 13
  • 4
0

I got result by using of below code,

TelephonyManager telephonyMananger = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String mobNumber = telephonyMananger.getLine1Number();
Vishal Vaishnav
  • 3,346
  • 3
  • 26
  • 57