Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><em>1</em> Disconnecting internet cables is irrelevant. Use F8 to switch off/on internet in the emulator</p> <p><em>2</em> In the first code this logic is wrong:</p> <pre><code>if(info != null || info.isConnected()) { Log.v("NetworkInfo","Connected State"); } </code></pre> <p>It should be:</p> <pre><code>if(info != null &amp;&amp; info.isConnected()) { Log.v("NetworkInfo","Connected State"); } </code></pre> <p>If you use || then this is the result: a) when info is null, info.isConnected() will crash b) when info is not null, you will always show Connected State</p> <p>However, even if you fix that, the code wont be completely correct (see <em>4</em>)</p> <p><em>3</em> In the second code, this logic is wrong:</p> <pre><code> else if ( conMgr.getNetworkInfo(1).getState() == NetworkInfo.State.DISCONNECTED || conMgr.getNetworkInfo(0).getState() == NetworkInfo.State.DISCONNECTED) { Log.v("conMgr"," No Connection"); } </code></pre> <p>should be:</p> <pre><code> else { Log.v("conMgr"," No Connection"); } </code></pre> <p>Why? Because there are more states than CONNECTED and DISCONNECTED.</p> <p>However, even if you fix that, the code wont be completely correct (see <em>4</em>)</p> <p><em>4</em> This works on emulator and devices. </p> <pre><code>connected = ( conMgr.getActiveNetworkInfo() != null &amp;&amp; conMgr.getActiveNetworkInfo().isAvailable() &amp;&amp; conMgr.getActiveNetworkInfo().isConnected() ) </code></pre> <p>Note the use of isAvailable - without this isConnected can return TRUE when WIFI is disabled.</p> <p>Hope this helps!</p>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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