0

I have asked the following quoted question but found that all working gone in vain as android is now not allowing to register the broadcast for network changes.

You can not do it in Manifest where as you can still get calls when you register it in your Activity and that context is still alive .

Now I have implemented in my activity and I am getting my broadcast receivers call and all is working as expected. But when I do start my activity , I received the call automatically. Can not I just skipp that thing on activity start ?

here is my old question that I have asked in this thread:

I have an application where I have implemented the BroadcastReceiver for the Network changes.

It alerts me when there is any change in the network connection, Like the network gets disconnected, the network gets connected, the network gets changed etc

But I have observe that it does not alert me when the Wifi is connected but the Internet goes off from that network.

Is there something to check such case and can we make broadcast for it ??

I have searched alot but did not get any answer of this. I hope I made myself quiet clear about my requirements.

A.s.ALI
  • 1,992
  • 3
  • 22
  • 54
  • System will not broadcast this . You need to ping to check for active connection . See https://stackoverflow.com/questions/17717749/check-for-active-internet-connection-android. – ADM Oct 19 '18 at 09:47
  • Possible duplicate of [How to check internet access on Android? InetAddress never times out](https://stackoverflow.com/questions/1560788/how-to-check-internet-access-on-android-inetaddress-never-times-out) – Markus Kauppinen Oct 19 '18 at 10:40

1 Answers1

0

Have you check the documentation here?

https://developer.android.com/training/monitoring-device-state/connectivity-monitoring?hl=es-419

It explains you how to use ConnectivityManager to check the changes on connectivity

ConnectivityManager cm =
    (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);

NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean isConnected = activeNetwork != null &&
                  activeNetwork.isConnectedOrConnecting();

You can even check the type:

boolean isWiFi = activeNetwork.getType() == ConnectivityManager.TYPE_WIFI;

Or even allow your app (via the Manifest) to consider the changes, by supporting this action:

<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>