I just created an android app for fetching data from website.I want to check there is a device having internet connection or not.If the device has internet connection running my code and fetch data from website and display otherwise the device has no internet connection means display the no internet connection message.I have tried this code to check the internet connection.How can I call the code when the connection has internet?
My java code
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_primary);
new FetchWebsiteData().execute();
}
});

}

private class FetchWebsiteData extends AsyncTask {
String websiteTitle, websiteDescription,websiteDescription1,websiteDesc ription2,websiteDescription3,listValue,listValue1;
ProgressDialog progress;
private Context context;

//check Internet connection.
private void checkInternetConnection(){

ConnectivityManager check = (ConnectivityManager) this.context.
getSystemService(Context.CONNECTIVITY_SERVICE);
if (check != null)
{
NetworkInfo[] info = check.getAllNetworkInfo();
if (info != null)
for (int i = 0; i