Is there a event which tells me that the device has connected to INTERNET (3G or wifi)? I need to start some request only after device connects to INTERNET. The code needs t
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 are able to know device have internet connected of not. I hope this is help full to you.