public static boolean connectionCheck(final Context context) { boolean returnTemp=true; ConnectivityManager conManager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo i = conManager.getActiveNetworkInfo(); if ((i == null)||(!i.isConnected())||(!i.isAvailable())) { AlertDialog.Builder dialog = new Builder(context); dialog.setTitle("CONNECTION STATUS"); dialog.setMessage("Failed"); dialog.setCancelable(false); dialog.setPositiveButton("Ok",new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { WifiManager wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE); wifiManager.setWifiEnabled(true); Toast.makeText(TennisAppActivity.mContext,"Wi-Fi On", Toast.LENGTH_LONG).show(); } }); dialog.show(); return false; } return true;`enter code here` }
Using this function, you can know that the device is connected to the Internet. Hope this helps you.
source share