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();
}
}
}
Manifest.xml
<receiver android:name="com.astrobix.service.Information" >
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
<action android:name="android.net.wifi.WIFI_STATE_CHANGED" />
</intent-filter>
</receiver>
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 RahuActivity.nextAlaram()
shows an exception.
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