2

I want to know that how I can get actual phone number from sim card instead of sim serial number.I have also tried (manager.getLine1Number) but it is giving me null.

jabir khan
  • 21
  • 1
  • 6

2 Answers2

1

A null reference might indicate that the phone number can not be accessed.

Documentation:

Note that access to some telephony information is permission-protected. Your application cannot access the protected information unless it has the appropriate permissions declared in its manifest file. Where permissions apply, they are noted in the the methods through which you access the protected information.

Required permissions:

READ_PHONE_STATE, READ_SMS, READ_PHONE_NUMBERS link to method doc

I have also found another question facing a quite similar issue "not working" with the method you named. Someone mentioned a duplicate question there, too. This could also be helpful: Link

If the code there is not helping you, I would recommend checking the exact documentation of your method to find details, why the null reference has been returned.

CrimsonMike
  • 263
  • 1
  • 13
1

Ref: How to get the mobile number of current sim card in real device?

TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE); 
String number = tm.getLine1Number();

The documentation for getLine1Number() says this method will return null if the number is "unavailable", but it does not say when the number might be unavailable.

You'll need to give your application permission to make this query by adding the following to your Manifest:

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

(You shouldn't use TelephonyManager.getDefault() to get the TelephonyManager as that is a private undocumented API call and may change in future.)

OR

Ref: TelephonyManager give me null

> getLine1Number(); returns whatever is stored on the SIM card's MSISDN,
> which isn't filled by some operators.

In your case i am pretty much sure The MSISDN is unfilled.

You should keep one thing in mind.

getLine1Number() sometimes return with null value or with the phone number originally stored in SIM card.

Ashvin solanki
  • 4,802
  • 3
  • 25
  • 65
  • appreciate your answer, but i have already used all things and also added the permission you have mentioned but it didn't work . So I will be thankful if there is any other way to find sim card number (actual phone number) from sim card. – jabir khan Aug 28 '18 at 08:52
  • and if testing on emulator is doesn't have mobile number @jabirkhan – Ashvin solanki Aug 28 '18 at 09:00
  • I get your point but I would like to know if there is any way to get the phone number from sim card or not?@Ashvin solanki – jabir khan Aug 28 '18 at 09:29
  • i already mention that in last point and reference Que @jabirkhan – Ashvin solanki Aug 28 '18 at 09:47