【问题标题】:Set Current Network Type设置当前网络类型
【发布时间】:2015-03-02 16:03:27
【问题描述】:

各位下午好,我遇到了 Android 问题。 我可以使用getNetworkType() 获取数据网络的当前状态,但是 如何设置数据网络的当前状态?

谢谢大家,对不起我的英语不好。

【问题讨论】:

  • 您想确定您拥有什么类型的网络?? “如何设置数据网络的当前状态”是什么意思?
  • 我不想确定我拥有什么类型的网络。我想在使用3G网络的同时用按钮打开4G网络,希望已经清楚

标签: android android-networking


【解决方案1】:

您不应该手动设置它。为什么需要这个?

如果您的意思是“检查移动数据传输是否开启”,您可以使用:

public boolean systemMobileStatusIsOn()
{
    try {
        Class cmClass = Class.forName(cm.getClass().getName());
        Method method = cmClass.getDeclaredMethod("getMobileDataEnabled");
        method.setAccessible(true); // Make the method callable
        // get the setting for "mobile data"
        return (Boolean)method.invoke(cm);
    } catch (Exception e) {
        // Some problem accessible private API
        // TODO do whatever error handling you want here
        return false;
    }
}

【讨论】:

  • 非常感谢您的回答,但我不想检查移动数据传输是否开启。
猜你喜欢
  • 1970-01-01
  • 2011-12-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-15
  • 2023-03-25
  • 2020-12-17
相关资源
最近更新 更多