Java tutorial
//package com.java2s; import android.app.Activity; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; public class Main { public static boolean hasInternet(Activity activity) { ConnectivityManager manager = (ConnectivityManager) activity .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = manager.getActiveNetworkInfo(); if (info == null || !info.isConnected()) { return false; } if (info.isRoaming()) { // here is the roaming option you can change it if you want to // disable internet while roaming, just return false return true; } return true; } }