Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try this.</p> <p>this will tell if you if you're connected to a network:</p> <pre><code>boolean connected = false; ConnectivityManager connectivityManager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); if(connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState() == NetworkInfo.State.CONNECTED || connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED) { //we are connected to a network connected = true; } else connected = false; </code></pre> <p>Warning: If you are connected to a WiFi network that doesn't include internet access or requires browser-based authentication, connected will still be true.</p> <pre><code>you will need this permission in your manifest: &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt; </code></pre> <p>Just use this function to check whether the Internet connection is available or not:</p> <pre><code>/** * Checks if the device has Internet connection. * * @return &lt;code&gt;true&lt;/code&gt; if the phone is connected to the Internet. */ public static boolean checkNetworkConnection(Context context) { final ConnectivityManager connMgr = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); final android.net.NetworkInfo wifi =connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI); final android.net.NetworkInfo mobile =connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if(wifi.isAvailable()||mobile.isAvailable()) return true; else return false; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload