For single SIM following code works:
TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
String imei= tm.getDeviceId();
TelephonyManager telephony = (TelephonyManager) this.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("getDeviceId", parameter);
Log.d("SimData", getFirstMethod.toString());
Object[] obParameter = new Object[1];
obParameter[0] = 0;
TelephonyManager manager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
String first = (String) getFirstMethod.invoke(telephony, obParameter);
Log.d("SimData", "first :" + first);
obParameter[0] = 1;
String second = (String) getFirstMethod.invoke(telephony, obParameter);
Log.d("SimData", "Second :" + second);
} catch (Exception e) {
e.printStackTrace();
}
try using this,this should help getting both device id on android lollipop