Get IMEI of both sim slots in two Android mobile phones

I am creating a mobile phone application with two sim phones. The application must be able to detect the sim through which the user makes the call. This can be an outgoing or incoming call. I tried to get both device IMEI devices using this tutorial . But it returns null for the second IMEI no.

How should I determine which sim user is using when making or receiving a call.

Please offer any way to achieve this.

+3
source share
2 answers

To view the status of a SIM1 type in the console:

adb shell dumpsys telephony.registry

To view the status of a SIM2 type in the console:

adb shell dumpsys telephony.registry2

mCallState / . , SIM-

dumpsys Java-, android.permission.DUMP . ( " " ).

+3

imei .

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

}

0

All Articles