<分区>
我将我的手机用于个人/工作线路,使用 dualsim(现在是小米 Mi5)和 Android 7。 我正在寻找一种方法来使用我的工作线(第二张 sim 卡)在周一至周五早上 6 点开机并在下午 22 点下类。
找了一些应用,android中的api自己做了,能找到实现的方法。
谢谢
<分区>
我将我的手机用于个人/工作线路,使用 dualsim(现在是小米 Mi5)和 Android 7。 我正在寻找一种方法来使用我的工作线(第二张 sim 卡)在周一至周五早上 6 点开机并在下午 22 点下类。
找了一些应用,android中的api自己做了,能找到实现的方法。
谢谢
最佳答案
有一个名为Dual SIM Control 的应用程序可以管理数据并与 Tasker 兼容,但价格为 1.20 欧元。您可以尝试 free version 中的功能(应用程序不再可用)。它声称无需 root 即可工作,但我不知道它是如何工作的。
我研究了一下,发现以下方法可以在 SDK 版本高于 22 的双卡手机中关闭一张 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;
}
}
}
关于Android DualSim,每天同一时间关闭第二个SIM卡的方法/任务/API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43386739/