to get phone number programmatically in Android

馋奶兔 提交于 2019-11-27 08:56:15
Maidul

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.

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()

Look for TelephonyManager.getSubscriberId(), this will give the unique id for each SIM.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!