Android DualSim,每天在同一时间关闭第二张SIM卡的方法/任务/api



我使用双卡双待(现在的小米Mi5)和Android 7使用我的手机进行个人/工作线。 我正在寻找一种方法来使用我的工作线(第二个 sim)在周一至周五早上 6 点打开并在晚上 22:00 下车。

在寻找一些应用程序后,android中的api自己制作,可以找到实现它的方法。

谢谢

软件解决方案

有一个名为双SIM卡控制的应用程序可以管理数据并与Tasker兼容,但价格为1.20欧元。您可以在免费版本中试用该功能(应用程序不再可用)。它声称可以在没有root的情况下工作,但我不知道它是如何工作的。

带根的解决方案

我研究了一下,发现以下内容可以关闭SDK版本高于22的双SIM卡手机中一张SIM卡的数据:

作者: https://stackoverflow.com/users/463053/chuongpham

public static void setMobileNetworkfromLollipop(Context context) throws Exception {
String transactionCode = getTransactionCode(context);
String command = null;
SubscriptionManager mSubscriptionManager = (SubscriptionManager) context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
// Loop through the subscription list i.e. SIM list.
for (int i = 0; i < mSubscriptionManager.getActiveSubscriptionInfoCountMax(); i++) {
if (transactionCode != null && transactionCode.length() > 0) {
// Get the active subscription ID for a given SIM card.
int subscriptionId = mSubscriptionManager.getActiveSubscriptionInfoList().get(i).getSubscriptionId();
// Execute the command via `su` to turn off
// mobile network for a subscription service.
command = "service call phone " + transactionCode + " i32 " + subscriptionId + " i32 " + Settings.Global.getInt(context.getContentResolver(), "mobile_data", 0);
executeCommandViaSu(context, "-c", command);
}
}
}

private static void executeCommandViaSu(Context context, String option, String command) {
boolean success = false;
String su = "su";
for (int i=0; i < 3; i++) {
// Default "su" command executed successfully, then quit.
if (success) {
break;
}
// Else, execute other "su" commands.
if (i == 1) {
su = "/system/xbin/su";
} else if (i == 2) {
su = "/system/bin/su";
}
try {
// Execute command as "su".
Runtime.getRuntime().exec(new String[]{su, option, command});
} catch (IOException e) {
success = false;
// Oops! Cannot execute `su` for some reason.
// Log error here.
} finally {
success = true;
}
}
}