to get phone number programmatically in Android
With API Level greater than or equal to 22 : You can access all the SIM details using SubscritionManager. Use following command to list all Sim numbers(Works well for Dual Sim also):
List<SubscriptionInfo> list = SubscriptionManager.from(getApplicationContext()).getActiveSubscriptionInfoList();
for(SubscriptionInfo s : list){
Log.d("SIMMANAGER",s.getNumber());
}
Note : This only works well when the operator stored their mobile number in sim card. Else, this method returns null.
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.
Look for TelephonyManager.getSubscriberId(), this will give the unique id for each SIM.
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()