Commons.java 文件源码

java
阅读 33 收藏 0 点赞 0 评论 0

项目:WiFiAPManager 作者:
public static void setMobileNetworkfromLollipop(Context context)
        throws InvocationTargetException, ClassNotFoundException,
        NoSuchMethodException, IllegalAccessException, NoSuchFieldException {
    String command;
    int state;
    // Get the current state of the mobile network.
    state = isMobileDataEnabled(context) ? 0 : 1;
    // Get the value of the "TRANSACTION_setDataEnabled" field.
    String transactionCode = getTransactionCode(context);
    // Android 5.1+ (API 22) and later.
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
        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.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 " + state;
                ShellUtils.execCommand(command, true);
            }
        }
    } else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP) {
        // Android 5.0 (API 21) only.
        if (transactionCode.length() > 0) {
            // Execute the command via `su` to turn off mobile network.
            command = "service call phone " + transactionCode + " i32 " + state;
            ShellUtils.execCommand(command, true);
        }
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号