Does network.setStatusListener work on Android?

Does network.setStatusListener work on Android? 

http://docs.coronalabs.com/daily/api/library/network/setStatusListener.html

I want to check if the user has an internet connection before attempting to display a webView in my app and the above api seems like the best way to go.

Thanks!

I’ve been using the following code snippet which I think I got off the forum sometime last year. Seems to imply that the network.setStatusListener does not work on Android and hence the alternate check. Do note the alternate check simply verifies that the device is connected to a network but does not actually verify internet connection direct to a host as network.setStatusListener would do. This is a shortcoming of course. Anyways, for what its worth… 

I would love to see some better ways of going about this. Thanks!

 if system.getInfo( "platformName" ) == "Android" then local status = network.getConnectionStatus() if status.isConnected then gotConnection = true -- trigger download function here end else if network.canDetectNetworkStatusChanges then network.setStatusListener( "www.google.com", MyNetworkReachabilityListener ) --MyNetworkReachabilityListener triggers download function print("Waiting for network response") else print("network reachability not supported on this platform") native.showAlert( "Network Error", "Network reachability not supported on this platform.", {"OK"} ) end end

Thanks for sharing this. Appreciate it!

You’re most welcome. 

I’ve been using the following code snippet which I think I got off the forum sometime last year. Seems to imply that the network.setStatusListener does not work on Android and hence the alternate check. Do note the alternate check simply verifies that the device is connected to a network but does not actually verify internet connection direct to a host as network.setStatusListener would do. This is a shortcoming of course. Anyways, for what its worth… 

I would love to see some better ways of going about this. Thanks!

 if system.getInfo( "platformName" ) == "Android" then local status = network.getConnectionStatus() if status.isConnected then gotConnection = true -- trigger download function here end else if network.canDetectNetworkStatusChanges then network.setStatusListener( "www.google.com", MyNetworkReachabilityListener ) --MyNetworkReachabilityListener triggers download function print("Waiting for network response") else print("network reachability not supported on this platform") native.showAlert( "Network Error", "Network reachability not supported on this platform.", {"OK"} ) end end

Thanks for sharing this. Appreciate it!

You’re most welcome. 

First off - I’m not an expert and currently researching the internet connectivity thing - so have not tried any of these as yet.

I did  a search and found this  (http://lazywombat.co.uk/how-to-check-a-device-is-connected-to-the-internet-using-corona-sdk/)

  • This guy created a module using socket - so using  my uninformed logic - would it not get the result required non-dependent on device make - correct??

Also - I can’t seem to find any Docs on - network.getConnectionStatus()

Overview

The networkStatus event is used in connection with network.setStatusListener() to determine whether a specific host is reachable.

A good 3rd-party documentation on how reachability works on iOS/Mac can be found at http://blog.ddg.com/?p=24.

Properties
event.name

event.isReachableViaWiFi

event.isReachableViaCellular

event.address

event.isInteractionRequired

event.isConnectionOnDemand

event.isReachable

event.isConnectionRequired
 

 

Any links to info on the call?

T.

First off - I’m not an expert and currently researching the internet connectivity thing - so have not tried any of these as yet.

I did  a search and found this  (http://lazywombat.co.uk/how-to-check-a-device-is-connected-to-the-internet-using-corona-sdk/)

  • This guy created a module using socket - so using  my uninformed logic - would it not get the result required non-dependent on device make - correct??

Also - I can’t seem to find any Docs on - network.getConnectionStatus()

Overview

The networkStatus event is used in connection with network.setStatusListener() to determine whether a specific host is reachable.

A good 3rd-party documentation on how reachability works on iOS/Mac can be found at http://blog.ddg.com/?p=24.

Properties
event.name

event.isReachableViaWiFi

event.isReachableViaCellular

event.address

event.isInteractionRequired

event.isConnectionOnDemand

event.isReachable

event.isConnectionRequired
 

 

Any links to info on the call?

T.