Here is how you can check the internet connection in your Android testing device. This works for G1, Hero, Droid etc.
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.setIcon(R.drawable.warning);
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