How to get network state change on android?
<p>I have broadcast receiver for "CONNECTIVITY_CHANGE". When I print the extra using this: </p>

<pre><code>intent.getExtras().toString() 
</code></pre>

<p>I can see that if I disable WIFI, I receive 2 network change. </p>

<ol>
<li>WIFI DISCONNECTED </li>
<li>MOBILE CONNECTED</li>
</ol>

<p>However, when I try to use</p>

<pre><code>NetworkInfo networkInfo = intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
</code></pre>

<p>It said, this API has been deprecated.  After that, I tried to use this</p>

<pre><code>int networkType = intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_TYPE);
NetworkInfo networkInfo = connectivityManager.getNetworkInfo(networkType);
</code></pre>

<p>However, getNetworkInfo also has been deprecated.</p>

<p>The only option they give me was using getActiveNetworkInfo or getActiveNetwork.</p>

<p>If I use that, I will get 2 broadcast which will give me same network info.</p>

<p>Is there a better way to handle network state in Android ?</p>

<p>EXTRA NOTE:</p>

<p>Thanks for quick reply, but I am not looking for a way to check if I have internet connection or not. </p>

<p>I need to know which network has been disconnected and connected. The network state change is what I am looking for.</p>