【问题标题】:how to force close wifi and data roaming如何强制关闭wifi和数据漫游
【发布时间】:2012-11-22 20:24:27
【问题描述】:

我想手动关闭 wifi 和 android 中的数据漫游。在处理完一些数据后,我想重新启用它。我怎样才能以编程方式做到这一点?

我只找到这个方法,但在我的 android 4 中不起作用。

How do I program android to look for a particular network?

【问题讨论】:

    标签: android


    【解决方案1】:

    对于wifi(需要android.permission.CHANGE_WIFI_STATE):

    WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    wm.setWifiEnabled(true);
    

    对于数据(需要android.permission.CHANGE_NETWORK_STATE,来自here):

    ConnectivityManager mgr = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
    Method dataMtd = ConnectivityManager.class.getDeclaredMethod("setMobileDataEnabled", boolean.class);
    dataMtd.setAccessible(true);
    dataMtd.invoke(mgr, true/false); 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多