Last active
July 8, 2016 09:39
-
-
Save pranaypatel512/a8e560294fd8fd9431870b463dbace19 to your computer and use it in GitHub Desktop.
network utils Class of an application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.karconnect.app.utils; | |
import android.content.Context; | |
import android.content.DialogInterface; | |
import android.net.ConnectivityManager; | |
import android.net.NetworkInfo; | |
import android.support.v7.app.AlertDialog; | |
public class NetworkUtils { | |
public static boolean isInternetAvailable(Context ctx) { | |
ConnectivityManager cm = (ConnectivityManager) ctx | |
.getSystemService(Context.CONNECTIVITY_SERVICE); | |
NetworkInfo netInfo = cm.getActiveNetworkInfo(); | |
if (netInfo != null && netInfo.isConnectedOrConnecting() | |
&& cm.getActiveNetworkInfo().isAvailable() | |
&& cm.getActiveNetworkInfo().isConnected()) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
public static void showNetworkAlertDialog(Context mCtx) { | |
AlertDialog.Builder builder = new AlertDialog.Builder(mCtx); | |
builder.setCancelable(false); | |
builder.setTitle("Connection"); | |
builder.setMessage("No internet available"); | |
builder.setPositiveButton("OK", | |
new DialogInterface.OnClickListener() { | |
@Override | |
public void onClick(DialogInterface dialog, int which) { | |
dialog.dismiss(); | |
} | |
}); | |
builder.create().show(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment