I have tried this code to check my mobile network connectivity
final ConnectivityManager connMgr = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
final android.net.NetworkInfo mobile =
connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
if( mobile.isAvailable() ){
Toast tst = Toast.makeText(this, "There is a network", Toast.LENGTH_SHORT);
tst.show();
}
else
{
Toast tst = Toast.makeText(this, "There is No network",Toast.LENGTH_SHORT);
tst.show();
}
The program always says “There is No network”, although, there is a network.
Maybe because I am using a 2G Sim Card and this method works for 3G. Any clue?
I guess you want telephony status, not data status.
Try with a different API.
http://developer.android.com/reference/android/telephony/ServiceState.html
This may work.
http://developer.android.com/reference/android/telephony/TelephonyManager.html
May be handy aswell.