How to check which sim is installed as a standard sim in android programmatically

I'm trying to check if my mobile device is dual sim, if sim1 is ready, if sim2 is ready, I ended up using java reflection, now I want to find out if sim1 isRoaming and if sim2 isRoaming, and if its dual sim, for which sim is installed by default. Is this possible with java reflection.

+4
source share
1 answer

You can do something like this:

public int getDefaultSimmm(Context context) { Object tm = context.getSystemService(Context.TELEPHONY_SERVICE); Method method_getDefaultSim; int defaultSimm = -1; try { method_getDefaultSim = tm.getClass().getDeclaredMethod("getDefaultSim"); method_getDefaultSim.setAccessible(true); defaultSimm = (Integer) method_getDefaultSim.invoke(tm); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } Method method_getSmsDefaultSim; int smsDefaultSim = -1; try { method_getSmsDefaultSim = tm.getClass().getDeclaredMethod("getSmsDefaultSim"); smsDefaultSim = (Integer) method_getSmsDefaultSim.invoke(tm); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return smsDefaultSim; } 
+4
source

All Articles