kittu88
kittu88

Reputation: 2461

Get IMEI of both sim slots in dual sim android mobile devices

I am creating an application for dual sim mobile phones. The application should be able to detect the sim through which the user is making a call. It can be outgoing or incoming call. I have tried to get both the IMEI nos of the device using this tutorial. But it returns null for the second IMEI no.

Any how I have to detect which sim the user is using while making or receiving a call.

Please suggest any way to achieve this.

Upvotes: 3

Views: 3834

Answers (2)

user6676551
user6676551

Reputation: 1

this might give you both imei of phone which has dual sim.

    public static void samsungTwoSims(Context context) {
TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

try{

    Class<?> telephonyClass = Class.forName(telephony.getClass().getName());

    Class<?>[] parameter = new Class[1];
    parameter[0] = int.class;
    Method getFirstMethod = telephonyClass.getMethod("getDefault", parameter);

    Log.d(TAG, getFirstMethod.toString());

    Object[] obParameter = new Object[1];
    obParameter[0] = 0;
    TelephonyManager first = (TelephonyManager) getFirstMethod.invoke(null, obParameter);

    Log.d(TAG, "Device Id: " + first.getDeviceId() + ", device status: " + first.getSimState() + ", operator: " + first.getNetworkOperator() + "/" + first.getNetworkOperatorName());

    obParameter[0] = 1;
    TelephonyManager second = (TelephonyManager) getFirstMethod.invoke(null, obParameter);

    Log.d(TAG, "Device Id: " + second.getDeviceId() + ", device status: " + second.getSimState()+ ", operator: " + second.getNetworkOperator() + "/" + second.getNetworkOperatorName());
} catch (Exception e) {
    e.printStackTrace();
}   

}

Upvotes: 0

eGregory
eGregory

Reputation: 121

To see state of SIM1 type in console:

adb shell dumpsys telephony.registry

To see state of SIM2 type in console:

adb shell dumpsys telephony.registry2

mCallState changed on incoming/outgoing call. It allow to let you know which SIM card used for call

When you invoke dumpsys from Java-application, you need android.permission.DUMP in manifest. But it does not work on some new devices (they fail with "Permission Denial").

Upvotes: 3

Related Questions