Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to check Net and WI-FI Availability
    primarykey
    data
    text
    <pre><code>public class Information extends BroadcastReceiver{ public static String ChangeDate; @Override public void onReceive(Context context, Intent intent) { ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); android.net.NetworkInfo wifi = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI); android.net.NetworkInfo mobile = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (wifi.isAvailable() || mobile.isAvailable()) { Toast.makeText(context, "Internet Available", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(context, "Internet not Available", Toast.LENGTH_SHORT).show(); RahuActivity.nextAlaram(); } } } </code></pre> <p><strong>Manifest.xml</strong></p> <pre><code> &lt;receiver android:name="com.astrobix.service.Information" &gt; &lt;intent-filter&gt; &lt;action android:name="android.net.conn.CONNECTIVITY_CHANGE" /&gt; &lt;action android:name="android.net.wifi.WIFI_STATE_CHANGED" /&gt; &lt;/intent-filter&gt; &lt;/receiver&gt; </code></pre> <p>Please anyone help me when I run this code on my mobile it shows both Toast methods. When I turn off Wi-Fi at first it show me Internet Available message and again show me Internet not Available message. It must show only onemessage, I think that's why my <code>RahuActivity.nextAlaram()</code> shows an exception.</p> <pre><code>Logcat here :- 08-02 16:25:54.309: E/AndroidRuntime(21170): java.lang.RuntimeException: Unable to start receiver com.astrobix.service.Information: java.lang.NullPointerException </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.
 

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