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.
-
Maybe you look [here](http://stackoverflow.com/questions/13472951/get-both-sim-numbers-in-a-dual-sim-android-phone) – MrT Aug 19 '15 at 07:24
-
can anyone tell me how to use getDefaultSim() method. I am trying to use it but it returns null. – Developine Aug 19 '15 at 09:29
-
TelephonyManager﹕ getDefaultSim is sim1. This appears in my LogCat file, Can i read this programatically from LogCat file. – Developine Aug 19 '15 at 09:33
3 Answers
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;
}

- 337
- 3
- 10
-
-
Always getting 0, If I selected default SIM for make call/ selected 2nd sim card. – Vineesh TP Jun 27 '17 at 04:07
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

- 148
- 1
- 14
A very late answer but I got into developing an application which has the above requirement
Below is the latest way to get it done.
/**
* @return - True - if any sim selected as default sim , False - No default sim is selected or
* permission for reading the sim status is not enabled
*/
boolean isDefaultSimSetForCall() {
if (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
Log.d(Utils.getTag(), "Read Phone state permission Disabled");
genericCallbacks.onPermissionAccessError(Constants.PermissionErrorCodes.READ_PHONE_STATE_ACCESS);
return false;
} else {
PhoneAccountHandle defaultPhoneAccount = telecomManager.getDefaultOutgoingPhoneAccount(Uri.fromParts("tel", "text", null).getScheme());
if (defaultPhoneAccount != null) {
Log.d(Utils.getTag(), "DefaultOutgoingPhoneAccount: " + defaultPhoneAccount.getId());
return true;
}
}
return false;
}
From the received PhoneAccountHandle, we can get the necessary fields

- 21
- 1
-
This works for me. Why not putting `"tel"` as parameter ? Also, what other types of parameter values can be used here? – android developer Jul 17 '23 at 10:54