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

标签 android dual-sim

我试过设置移动数据。但它只适用于 SIM 1

public static void setMobileData(Context context, boolean isEnabled) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {

    ConnectivityManager conman = (ConnectivityManager) context.getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
    @SuppressWarnings("rawtypes")
    final Class conmanClass = Class.forName(conman.getClass().getName());
    final Field iConnectivityManagerField = conmanClass.getDeclaredField("mService");
    iConnectivityManagerField.setAccessible(true);
    final Object iConnectivityManager = iConnectivityManagerField.get(conman);
    final Class iConnectivityManagerClass = Class.forName(iConnectivityManager.getClass().getName());

    Class[] cArg = new Class[2];
    cArg[0] = String.class;
    cArg[1] = Boolean.TYPE;
    Method setMobileDataEnabledMethod;

    setMobileDataEnabledMethod = iConnectivityManagerClass.getDeclaredMethod("setMobileDataEnabled", cArg);

    Object[] pArg = new Object[2];
    pArg[0] = context.getPackageName();
    pArg[1] = isEnabled;
    setMobileDataEnabledMethod.setAccessible(true);
    setMobileDataEnabledMethod.invoke(iConnectivityManager, pArg);
}

public static void setMobileData2(Context context, boolean isEnabled) throws NoSuchMethodException, ClassNotFoundException, IllegalAccessException, NoSuchFieldException, InvocationTargetException {
    final ConnectivityManager conman = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    final Class conmanClass = Class.forName(conman.getClass().getName());
    final Field iConnectivityManagerField = conmanClass.getDeclaredField("mService");
    iConnectivityManagerField.setAccessible(true);
    final Object iConnectivityManager = iConnectivityManagerField.get(conman);
    final Class iConnectivityManagerClass = Class.forName(iConnectivityManager.getClass().getName());
    final Method setMobileDataEnabledMethod = iConnectivityManagerClass.getDeclaredMethod("setMobileDataEnabled", Boolean.TYPE);
    setMobileDataEnabledMethod.setAccessible(true);

    setMobileDataEnabledMethod.invoke(iConnectivityManager, isEnabled);
}

public static boolean setMobileData3(Context context, boolean isEnable) {
    boolean mobileDataAllowed = Settings.Secure.putInt(context.getContentResolver(), "mobile_data", isEnable?1:0);
    return mobileDataAllowed;
}

但现在我只想启动默认的移动选择对话框。如果您对启动该对话框有任何想法,请告诉我。提前致谢。

.

最佳答案

多 SIM 卡支持仅在 android lollipop 5.1 及更高版本中添加。在此之前,不同的手机制造商有自己的自定义实现来支持多 SIM 卡和各自的设置。因此,如果您的目标是通用解决方案,则无法实现。即使在 5.1 上,也没有直接启动此特定设置的 Intent ,但如果制造商应仅使用 Google 解决方案,则您可以使用 hack 实现,否则它将无法工作。

关于android - 我需要做什么才能启动手机互联网设置对话框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34067443/

相关文章:

android - 慢速 Espresso

安卓信号强度

android - 在 Marshmallow 及以下 android 中通过 sim 插槽获取通话记录

java - 当用户退出应用程序/终止进程时,是否可以在 android 中执行脚本?

android - 带 Lint 的StackOverflowError

android - 如何从服务获取数据到 Activity

android - 在 Kitkat 上编译的 Lollipop 优化应用程序 - LayoutInflaterCompatHC NoClassDefFoundError

android - 从第二个 sim 调用

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

android - 如何在 Android 中区分双卡的数据/语音使用