其实我已经使用下面的代码来检查wifi是否活动(其工作正常)。 我只是想确认我可以使用相同的代码来检查3G激活状态:如何在我的应用程序中检查3G的状态:
public boolean checkwifi()
{
ConnectivityManager connec = (ConnectivityManager) this.getSystemService(this.CONNECTIVITY_SERVICE);
android.net.NetworkInfo wifi = connec.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
android.net.NetworkInfo mobile = connec.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
// Here if condition check for wifi and mobile network is available or not.
// If anyone of them is available or connected then it will return true, otherwise false;
if (wifi.isConnected()) {
return true;
}
else if (mobile.isConnected()) {
return true;
}
return false;
}
当您在手机上运行该代码时会发生什么?如果它给出正确的结果,那么你可以使用它。 –
希望这有助于http://stackoverflow.com/questions/3262781/how-to-check-wifi-or-3g-network-is-available-on-android-device和这个http://stackoverflow.com/questions/2919414 /获得网络类型 – dpp