59
You can do this, for various types of network status
public void checkNetworkStatus(){
final ConnectivityManager connMgr = (ConnectivityManager)
this.getSystemService(Context.CONNECTIVITY_SERVICE);
final android.net.NetworkInfo wifi =
connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
final android.net.NetworkInfo mobile =
connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
if( wifi.isAvailable() ){
Toast.makeText(this, "Wifi" , Toast.LENGTH_LONG).show();
}
else if( mobile.isAvailable() ){
Toast.makeText(this, "Mobile 3G " , Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(this, "No Network " , Toast.LENGTH_LONG).show();
}
}
You are not using ConnectivityManager.getNetworkInfo(0).getState() and ConnectivityManager.getNetworkInfo(1).getState() properly, instead of hardcoding the values (1) and (0) use ConnectivityManager.TYPE_WIFI and ConnectivityManager.TYPE_MOBILE