Starting SDK 22, Android officially support Dual-SIM and provide some documentation.
I would like to know if it is possible for an app to change wich SIM should access the network. For example I have a One Plus One 3T phone running Nougat and I use two SIM cards. Going into settings, I can manually change / select which SIM card to use to access the network.
Is it possible to achieve this ?
Thanks !
The solution I found for Android 7.1.1 API 25 is using SubscriptionManager and reflection api.
Note that you have to install your app in /system/priv-app/
You can do this through adb root.
Make sure you have in your AndroidManifest.xml
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE"/>
<uses-permission android:name="android.permission.WRITE_APN_SETTINGS"/>
The code is the following
The only thing this code does is exchange the sim data
private Integer subActual = null;
private Integer sim1 = null;
private Integer sim2 = null;
private SubscriptionInfo simInfo1;
private SubscriptionInfo simInfo2;
private Boolean dualSim;
SubscriptionManager subscriptionManager = SubscriptionManager.from(this);
@SuppressLint("MissingPermission")
List smList = subscriptionManager.getActiveSubscriptionInfoList();
Method[] smMethods = subscriptionManager.getClass().getMethods();
dualSim = smList.size() == 2;
if (dualSim) {
simInfo1 = (SubscriptionInfo) smList.get(0);
simInfo2 = (SubscriptionInfo) smList.get(1);
sim1 = simInfo1.getSubscriptionId();
sim2 = simInfo2.getSubscriptionId();
}
for (Method m : smMethods) {
if (m.getName().equals(("getDefaultDataSubscriptionId"))) {
try {
subActual = (int) m.invoke(subscriptionManager);
} catch (Exception e) {
}
}
}
for (Method m : smMethods) {
if (m.getName().equals("setDefaultDataSubId") && dualSim) {
try {
if (subActual == sim1) {
m.invoke(subscriptionManager, sim2);
}
if (subActual == sim2) {
m.invoke(subscriptionManager, sim1);
}
} catch (Exception e) {
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.