It’s a lot of Corona methods to handle app’s network status.
But all that stuff is for iOS/OSX only.
Sure, it runs great on my test iDevices. Hats off for Corona engineers, great job.
But i need something similar for Android version of my app too.
It’s not a big deal to pull a http requests continiously. But that’s quite a mess.
And server request reply is not instant - just because of host http request timeout.
Is there any strict/easy method/solution to check it out without continious pinging some distant host?
Hi,
I’m pretty sure the engineers can only access what’s available via the devices SDK. If anything, the issue is Android not supporting this fairly obvious piece of functionality. Perhaps engineering will chime in with more on why Corona or Android does not handle this event.
Pinging servers or data sources to check for availability is a pretty standard practice. If you’re looking for an “instant” check, I would try the socket library.
[lua]
– Check connectivity with socket
local function isOnline()
local sock = require( ‘socket’ )
local client, err = sock.connect(‘google.com’, 80)
if not client then
return nil, err
else
client:close()
return true, nil
end
end
[/lua]
And then of course using it…
[lua]
– Check connectivity (later)
local online, err = isOnline()
if not online then
print( "Uh Oh: " … err )
else
print( “I’m Online!” )
end
[/lua]
It’s not perfect, but it works. The main thing is pinging a solid endpoint (like Google), because you’re looking for connectivity, not whether the endpoint is available.
Hope that helps.
Cheers.
fwiw, there’s an undocumented network.getConnectionStatus() that does (or “did”, last i checked) work on Android (if you include ACCESS_NETWORK_STATE permission), but still may not fully do what you want… cuz just having a network connection doesn’t necessarily mean you can successfully DO some specific thing with it, so if you need to know for sure then you’re still better off opening a socket.
Thank you, such a nice way to solve this problem 
Hi,
I’m pretty sure the engineers can only access what’s available via the devices SDK. If anything, the issue is Android not supporting this fairly obvious piece of functionality. Perhaps engineering will chime in with more on why Corona or Android does not handle this event.
Pinging servers or data sources to check for availability is a pretty standard practice. If you’re looking for an “instant” check, I would try the socket library.
[lua]
– Check connectivity with socket
local function isOnline()
local sock = require( ‘socket’ )
local client, err = sock.connect(‘google.com’, 80)
if not client then
return nil, err
else
client:close()
return true, nil
end
end
[/lua]
And then of course using it…
[lua]
– Check connectivity (later)
local online, err = isOnline()
if not online then
print( "Uh Oh: " … err )
else
print( “I’m Online!” )
end
[/lua]
It’s not perfect, but it works. The main thing is pinging a solid endpoint (like Google), because you’re looking for connectivity, not whether the endpoint is available.
Hope that helps.
Cheers.
fwiw, there’s an undocumented network.getConnectionStatus() that does (or “did”, last i checked) work on Android (if you include ACCESS_NETWORK_STATE permission), but still may not fully do what you want… cuz just having a network connection doesn’t necessarily mean you can successfully DO some specific thing with it, so if you need to know for sure then you’re still better off opening a socket.
Thank you, such a nice way to solve this problem 