I am trying to check if my if my mobile device is dual sim, if sim1 is ready, if sim2 is ready, I am done with this using java reflection, now i want to find out if sim1 isRoaming and if sim2 isRoaming, and if its dual sim which sim is set as default. Is it possible with the help of java reflection.
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;
}
Starting from API 22 (Lollipop MR1) android has officially added SubscriptionManager
class which gives all the information required by the developer in relation to sim cards and related services.
Documentation for SubscriptionManager
However support for retrieving defaults for calls, SMS and Mobile data were added in API 24.
If you use your minimum SDK version to 24 you can use getDefaultSmsSubscriptionId()
method to get SMS default set by the user
SubscriptionManager manager = context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
int defaultSmsId = manager.getDefaultSmsSubscriptionId();
SubscriptionInfo info = manager.getActiveSubscriptionInfo(defaultSmsId);
Note: Above mention call requires READ_PHONE_STATE
permission. Make sure you add it in your manifest file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With