Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

to get phone number programmatically in Android

I am using the code

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

to get the phone no programatically in android . But this is working fine only for one sim card. If i test this code by inserting other sim card, it is giving null. I am trying to find the solution for this. please help me. I have also included READ_PHONE_STATE permission in Manifest.

I want to uniquely identify the sim card. IS there any other way to do this. please let me know.

like image 922
Prabhu M Avatar asked May 10 '11 10:05

Prabhu M


2 Answers

I think Sim serial Number is unique. You can try this.

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

Let me know if there is any issue.

like image 144
Maidul Avatar answered Nov 06 '22 04:11

Maidul


This is a known issue. Many SIM across the globe would return null. You should rather use IMEI number however even that can return null.

TelephonyManager.getDeviceId()
like image 1
PravinCG Avatar answered Nov 06 '22 04:11

PravinCG