Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get both phone number from dual SIM device?

Tags:

android

I know how to get user's phone number, but let's say the user's phone is dual SIM. Is there any way to get both phone numbers? Currently I am getting the active phone number only.

like image 444
Julfikar Avatar asked Feb 06 '23 05:02

Julfikar


1 Answers

If the phone number is indeed stored in the SIM card, then you can use subscriptionmanager API (https://developer.android.com/reference/android/telephony/SubscriptionManager.html) to get the details on each subscription i.e for each SIM card.

You can call

  • getActiveSubscriptionInfoList() which will return list. In your case if there are 2 SIM cards inserted, it should return 2 subscription infos
  • In subscription info, you can call getNumber() API (https://developer.android.com/reference/android/telephony/SubscriptionInfo.html#getNumber()) to get the number

Please note that for this to work, the SIM card should have the phone number in it.

Please note this API is only supported from API level 22

Adding example code :

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP_MR1) {
            SubscriptionManager subscriptionManager = SubscriptionManager.from(getApplicationContext());
            List<SubscriptionInfo> subsInfoList = subscriptionManager.getActiveSubscriptionInfoList();

            Log.d("Test", "Current list = " + subsInfoList);

            for (SubscriptionInfo subscriptionInfo : subsInfoList) {

                String number = subscriptionInfo.getNumber();

                Log.d("Test", " Number is  " + number);
            }
        }
like image 156
manishg Avatar answered Feb 15 '23 11:02

manishg