【发布时间】:2013-08-23 18:04:03
【问题描述】:
即使设备连接到 Wifi,我也希望允许用户切换 3G 状态(开/关)(我读到 here 说在连接到 Wifi 时禁用 3G 可以节省电池电量)。
但是,当我在设备连接到 Wifi 时检查 3G 状态时,它总是返回断开连接。
我的代码是:
// access to mobile networtk service - 3G
ConnectivityManager connManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mobile = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
// check mobile status
NetworkInfo.State state = mobile.getState(); // returns Disconnected
Boolean isConnected = mobile.isConnectedOrConnecting(); // returns false
if (isConnected)
{
// Turn 3G off
}
else
{
// Turn 3G on
}
【问题讨论】:
标签: android android-wifi