hello friends
today we are going to learn about one more topic. into this tutorials we are going to check network status means we are going to write a code for mobile data or wifi network are available or not in android.let's take a create a demo code.
public boolean mobiledata()
{
ConnectivityManager connectivityManager =
(ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
NetworkInfo mobileInfo =
connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
boolean mobileConnected = mobileInfo.getState() == NetworkInfo.State.CONNECTED;
return mobileConnected;
}
public boolean checkMobileInternetConn() {
Context _context = BrowserActivity.this;
ConnectivityManager connectivity = (ConnectivityManager) _context.getSystemService(Context.CONNECTIVITY_SERVICE);if (connectivity != null) {
NetworkInfo info = connectivity.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (info != null) {
if (info.isConnected()) {
return true;
}
}
}
return false;
}
Thanks.
today we are going to learn about one more topic. into this tutorials we are going to check network status means we are going to write a code for mobile data or wifi network are available or not in android.let's take a create a demo code.
public boolean mobiledata()
{
ConnectivityManager connectivityManager =
(ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
NetworkInfo mobileInfo =
connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
boolean mobileConnected = mobileInfo.getState() == NetworkInfo.State.CONNECTED;
return mobileConnected;
}
public boolean checkMobileInternetConn() {
Context _context = BrowserActivity.this;
ConnectivityManager connectivity = (ConnectivityManager) _context.getSystemService(Context.CONNECTIVITY_SERVICE);if (connectivity != null) {
NetworkInfo info = connectivity.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (info != null) {
if (info.isConnected()) {
return true;
}
}
}
return false;
}
Thanks.
Comments
Post a Comment