ConnectivityManager mgr = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = mgr.getActiveNetworkInfo();
if (netInfo != null) {
if (netInfo.isConnected()) {
// do something
} else {
AlertDialog.Builder alertbuilder = new AlertDialog.Builder(MyActivity.this);
alertbuilder.setTitle("Internet");
alertbuilder.setMessage("Internet is not available");
alertbuilder.setNeutralButton("Ok", okClickListener);
alertbuilder.show();
}
} else {
AlertDialog.Builder alertbuilder = new AlertDialog.Builder(
MyActivity.this);
alertbuilder.setTitle("Internet");
alertbuilder.setMessage("Internet is not available");
alertbuilder.setNeutralButton("Ok", okClickListener);
alertbuilder.show();
}
No comments:
Post a Comment