private void checkNetwork() {
ConnectivityManager connMgr =
(ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeInfo = connMgr.getActiveNetworkInfo();
if (activeInfo != null && activeInfo.isConnected()) {
wifiConnected = activeInfo.getType() == ConnectivityManager.TYPE_WIFI;
mobileConnected = activeInfo.getType() == ConnectivityManager.TYPE_MOBILE;
if(wifiConnected) {
Log.i(TAG, "WIFI connected");
} else if (mobileConnected){
Log.i(TAG, "Mobile Connected");
}
} else {
Log.i(TAG,"Neither Mobile nor WIFi connected.");
}
}
public static boolean isInternetActivorNot(Context context) {
ConnectivityManager cm = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm.getActiveNetworkInfo() != null
&& cm.getActiveNetworkInfo().isAvailable()
&& cm.getActiveNetworkInfo().isConnected()) {
Log.v("Util", "Internet is working");
return true;
} else {
Log.v("Util", "Internet Connection Not Present");
return false;
}
}
And also Don't miss add Following Permission in AndroidMainfst file ..
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
No comments:
Post a Comment