Raj Turakhia
Raj Turakhia

Reputation: 245

Programmatically getting Null or Blank device's Phone number in some devices

I have tried below code

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

Permission

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

I have tried in two device

  1. Micromax Canvas-4 (Getting user phone number)
  2. Htc desire 816G (Not able to get user phone number)

Please help me !! Your help will be appreciated. Thanks in advance.

Upvotes: 3

Views: 2645

Answers (1)

Sam
Sam

Reputation: 452

It is occurring because you need to set your own phone number on the device. please have a look at the below link.

getLine1Number() Returns blank, not null

This will solve your problem.

Upvotes: 1

Related Questions