Check Internet Newtwork Connection
Function for check internet connection
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
/** | |
* @param context | |
* @param message | |
* @return | |
* @author Mihir | |
* @description use to check internet newtwork connection | |
* if network connection not available than alert for open network settings | |
*/ | |
public static boolean isOnline(final Context context, boolean message) { | |
ConnectivityManager mConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); | |
NetworkInfo netInfo = mConnectivityManager.getActiveNetworkInfo(); | |
if (netInfo != null) { | |
if (netInfo.isConnectedOrConnecting()) { | |
return true; | |
} | |
} | |
if (message) { | |
AlertDialog.Builder builder = new AlertDialog.Builder(context); | |
builder.setMessage("Please check your network connection"); | |
builder.setCancelable(false); | |
builder.setPositiveButton("Network Settings", new DialogInterface.OnClickListener() { | |
@Override | |
public void onClick(DialogInterface dialog, int which) { | |
context.startActivity(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS)); | |
} | |
}); | |
builder.setNegativeButton("Wifi Settings", new DialogInterface.OnClickListener() { | |
@Override | |
public void onClick(DialogInterface dialog, int which) { | |
context.startActivity(new Intent(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK))); | |
} | |
}); | |
AlertDialog alert = builder.create(); | |
alert.show(); | |
return false; | |
} | |
return false; | |
} |
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
if(Common.isOnline(Category.this, true)) { | |
// put your code here | |
} |
Comments
Post a Comment