10

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.

Mike M.
  • 38,532
  • 8
  • 99
  • 95
Julfikar
  • 1,353
  • 2
  • 18
  • 35
  • Please check this http://stackoverflow.com/questions/13472951/get-both-sim-numbers-in-a-dual-sim-android-phone – vinod Jan 31 '17 at 03:18

2 Answers2

13

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

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);
            }
        }
manishg
  • 9,520
  • 1
  • 16
  • 19
0

I have Kotlinized @manishg code (from 5 years ago):

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
    val subscriptionManager = SubscriptionManager.from(applicationContext)
    val subsInfoList = subscriptionManager.activeSubscriptionInfoList
    Log.d("Test", "Current list = $subsInfoList")
    for (subscriptionInfo in subsInfoList) {
        val number = subscriptionInfo.number
        Log.d("Test", " Number is  $number")
    }
}

Note #1: you must add to the manifest:

uses-permission android:name="android.permission.READ_PHONE_STATE"

Note #2: you should have a permission check on your code, like:

  val subsInfoList = if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
                        //    ActivityCompat#requestPermissions
        return
    } else {
        //todo return "no permissions"
    }