Hi,
As the network API do not work for Android, how do you check network reachability on Android ?
Best,
Fred. [import]uid: 5578 topic_id: 37629 reply_id: 67629[/import]
Hi,
As the network API do not work for Android, how do you check network reachability on Android ?
Best,
Fred. [import]uid: 5578 topic_id: 37629 reply_id: 67629[/import]
Does the event.isReachable argument not work?
http://docs.coronalabs.com/daily/api/library/network/setStatusListener.html
The 3rd post in this link may also suffice:
http://developer.coronalabs.com/forum/2012/10/09/detecting-network-presence [import]uid: 6084 topic_id: 37629 reply_id: 145796[/import]
Thanks for your reply.
As said in the docs : “Please note that Reachability is only available on the Mac and iOS platforms. Android and Windows are not supported.”
So the work around should be a solution, not a nice one for a cross platform tools… [import]uid: 5578 topic_id: 37629 reply_id: 145819[/import]
Try this
function testNetworkConnection() print("testing connection") if http.request( "http://google.com/" ) == nil then print("cant connect to google") return false end print("got a connection") return true end
As of the newest daily build, we have a new undocumented network API called “network.getConnectionStatus()” that allows you to check if the device is currently connected to the network. It works like this…
[lua]
local status = network.getConnectionStatus()
if status.isConnected then
– Device is currently connected to a network.
end
if status.isMobile then
– Device has network access via cellular service.
else
– Device has network access via WiFi.
end
[/lua]
Please note that this API only detects if the device is connected to a network, which does not necessarily mean that you have Internet access. For example, “isConnected” will be set true if you are on a private LAN with no Internet access or one of those pay-to-use WiFi networks that you typically find at hotels or airports. But it is a fast check that works on both iOS and Android. The “isMobile” check is particularly useful to those who care about data usage.
On Android, you must set the following permission in your “build.settings” file in order to call this function…
[lua]
settings =
{
android =
{
usesPermissions =
{
“android.permission.ACCESS_NETWORK_STATE”
}
}
}
[/lua]
This API is currently not documented yet, but we plan on doing so in the near future.
Our new network API is fresh out of the oven after all.
In any case, I hope this helps!
Thanks for the undocumented function. It is what I need.
Wow, that’s a great add to the API. Thanks for the early heads up, Josh.
Does the event.isReachable argument not work?
http://docs.coronalabs.com/daily/api/library/network/setStatusListener.html
The 3rd post in this link may also suffice:
http://developer.coronalabs.com/forum/2012/10/09/detecting-network-presence [import]uid: 6084 topic_id: 37629 reply_id: 145796[/import]
Thanks for your reply.
As said in the docs : “Please note that Reachability is only available on the Mac and iOS platforms. Android and Windows are not supported.”
So the work around should be a solution, not a nice one for a cross platform tools… [import]uid: 5578 topic_id: 37629 reply_id: 145819[/import]
Try this
function testNetworkConnection() print("testing connection") if http.request( "http://google.com/" ) == nil then print("cant connect to google") return false end print("got a connection") return true end
As of the newest daily build, we have a new undocumented network API called “network.getConnectionStatus()” that allows you to check if the device is currently connected to the network. It works like this…
[lua]
local status = network.getConnectionStatus()
if status.isConnected then
– Device is currently connected to a network.
end
if status.isMobile then
– Device has network access via cellular service.
else
– Device has network access via WiFi.
end
[/lua]
Please note that this API only detects if the device is connected to a network, which does not necessarily mean that you have Internet access. For example, “isConnected” will be set true if you are on a private LAN with no Internet access or one of those pay-to-use WiFi networks that you typically find at hotels or airports. But it is a fast check that works on both iOS and Android. The “isMobile” check is particularly useful to those who care about data usage.
On Android, you must set the following permission in your “build.settings” file in order to call this function…
[lua]
settings =
{
android =
{
usesPermissions =
{
“android.permission.ACCESS_NETWORK_STATE”
}
}
}
[/lua]
This API is currently not documented yet, but we plan on doing so in the near future.
Our new network API is fresh out of the oven after all.
In any case, I hope this helps!
Thanks for the undocumented function. It is what I need.
Wow, that’s a great add to the API. Thanks for the early heads up, Josh.
This is just what I needed. Please document it. This is the 3rd undocumented feature that’s saved my butt. Are there any more? You should get an intern or someone to scour your code for these gems and update the docs!
This is just what I needed. Please document it. This is the 3rd undocumented feature that’s saved my butt. Are there any more? You should get an intern or someone to scour your code for these gems and update the docs!
I just found this post (which is a bit over a year old), but network.getConnectionStatus() is still undocumented.
It’s just what I need, but is it safe to use in production code?
This is a very needed feature! My app just crashes when you try to connect to socket without network. Is this safe to use?
My app just crashes when you try to connect to socket without network.
Exactly!
I’ve put this undocumented feature in my code, and it seems to work well so far, but I’m reluctant to ship until I get some verification that it’s safe to use…
I’ve been using it in production code for a year or so. No problems - that I’m aware of!