0

I was looking for a way to react a case when:

  • I am connected to WiFi
  • the access point has just lost internet connection (e.g the cable from router has been removed)

In such cases, Android phones or notebooks are notified about that state and showing exclamation mark next to the WiFi icon.

Is it possible to be notified about that state in Android API? I was looking in the documentation but not found any.

IMPORTANT NOTE: I am not looking for just checking internet connection manually or just listen for changing network connection status as I will not be notified when the WiFi access point that I am connected to has lost the connection.

So regarding above I was trying to just check the changes of the network connection, but as i explained it is not enough for my case:

override fun onReceive(context: Context, intent: Intent) {
val wifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, 
DEFAULT_WIFI_STATE_VALUE)
wifiStateSubject.onNext(wifiState)
Timber.d("Current wifi state: $wifiState")
}
K.Os
  • 5,123
  • 8
  • 40
  • 95
  • Lol.. what is this in connection to my question? Even better, there are better tools to react on events (Rx) – K.Os Oct 02 '18 at 07:40
  • you said `I was looking for a way to react a case` that's what this library do@Konrad – Ashwini Saini Oct 02 '18 at 07:42
  • That is the less important here (i have multiple way of reacting to events). What is interesting me is my event case (how to find it) – K.Os Oct 02 '18 at 07:48

1 Answers1

0

You can periodically try to access some resource with low ping and low timeout rate and if it throws some kind of NetworkException you can suppose that connection not available.

UPD:

You can use or inspect this library https://github.com/pwittchen/NetworkEvents

Anton Kazakov
  • 2,740
  • 3
  • 23
  • 34
  • Yes, i think this issue can be implemented on my own, but i wonder if there is some API which can provide me this specific status – K.Os Oct 02 '18 at 08:30
  • 2
    @Konrad well i don't know Class in Android SDK for this purpose. but you can use https://github.com/pwittchen/NetworkEvents this for example ir try to inspect SDK/github yourself ) – Anton Kazakov Oct 02 '18 at 08:32
  • Thanks, do you know if it also can check the cellular signal state? Like PhoneStateListener with TelephonyManager? – K.Os Oct 02 '18 at 09:36
  • @Konrad unfortunately i don't – Anton Kazakov Oct 02 '18 at 09:39