Friday, December 07, 2012

Internet Connection Check in Android


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:

Create a list in SwiftUI with sticky section headers

 Sample Code import SwiftUI struct ContentView : View {     @State var isCustomViewControllerDisplayed = false     @State private va...