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

标签 android api dual-sim

<分区>

我将我的手机用于个人/工作线路,使用 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/

相关文章:

android - 应用在特定的Android版本上崩溃

android - 需要在Android客户端调用Kurento Media Server opencv插件

android - 我需要做什么才能启动手机互联网设置对话框?

Android Espresso Ui 测试验证 ActionPage 的标签文本

java - 没有泛型的愚蠢证明迭代的API设计

java - API版本控制有哪些类型?

php php_replace 正则表达式\\\正斜杠

android - SubscriptionManager 为运行 Android 5.1+ 的双 SIM 卡设备读取 IMSI

android - 查看手机SIM槽总数

java - 将事件监听器附加到 Android UI 组件?