In my application data comes from internet and I am trying to create a function that checks if a internet connection is available or not and if it isn\'t, it gives an alert
public boolean isOnline()
{
ConnectivityManager connectionManager;
if(app_context!=null)
connectionManager = (ConnectivityManager) app_context.getSystemService(Context.CONNECTIVITY_SERVICE);
else
return false;
try
{
if (connectionManager.getActiveNetworkInfo().isConnected())
{
Log.e(THIS_FILE, "Communicator ....isConnected()");
return true;
}
else
{
Log.e(THIS_FILE, "Communicator ....isNotConnected()");
return false;
}
}
catch (NullPointerException e)
{
Log.e(THIS_FILE, "No Active Connection");
return false;
}
}
set permission in manifest