Network Reachability

Would anyone be able to help me with this? My code works fine on iOS, but doesn’t work when I test on Android devices.

[code]

function displayFeed(feedName, feedURL)

print(“entering displayFeed”)

local function processRSSFeed(file, path)
print(“Parsing the feed”)
–native.showAlert(“processRSSFeed”, “before rss.feed”, {“OK”})
local story = {}
stories = rss.feed(file, path)
if stories == nil then
local alert = native.showAlert( “We’re Sorry.”, “Looks like there is a problem connecting to the internet. Please make sure you are connected to the internet.”,
{ “OK” }, onAlertComplete )
else
–native.showAlert(“processRSSFeed”, “after rss.feed”, {“OK”})
–print_r(stories)
print("Num stories: " … #stories)
print("Got “, #stories, " stories, now show the tableView”)
showTableView()
end
end

local function onAlertComplete( event )
native.setActivityIndicator( false )
director:changeScene(“Region_Africa”)
return true
end

local networkListener = function( event )
utility.print_r(event)
if ( event.isError ) then
print(“Using Cached Copy”)
processRSSFeed(feedName, systemDocumentsDirectory)
else
print(“calling processRSSFeed because the feed is avaialble”)
processRSSFeed(feedName, system.DocumentsDirectory)
end
return true
end

function MyNetworkReachabilityListener(event)
–native.showAlert(“network”, “is reachable”, {“OK”})
print( “isReachable”, event.isReachable )
network.setStatusListener( “www.awanainternational.org”, nil )
if event.isReachable then
– download the latest file
native.setActivityIndicator( true )
–native.showAlert(“network”, “downloading”, {“OK”})
network.download(feedURL, “GET”, networkListener, feedName, system.DocumentsDirectory)
else
native.setActivityIndicator( true )
print(“not reachable”)
–native.showAlert(“network”, “using cached copy”, {“OK”})
– look for an existing copy
local path = system.pathForFile(feedName, system.DocumentsDirectory)
local fh, errStr = io.open( path, “r” )
if fh then
io.close(fh)
print(“calling processRSSfeed because the network isn’t reachable”)
processRSSFeed(feedName, system.DocumentsDirectory)
else
local alert = native.showAlert( “We’re Sorry.”, “Looks like there is a problem connecting to the internet. Please make sure you are connected to the internet.”,
{ “OK” }, onAlertComplete )
end
end
return true
end

local platform = system.getInfo(“platformName”)
if platform == “Android” then
– Android doesn’t support network detection at this point, so skip it.
native.setActivityIndicator( true )
network.download(feedURL, “GET”, networkListener, feedName, system.DocumentsDirectory)
else
if network.canDetectNetworkStatusChanges then
network.setStatusListener( “www.awanainternational.org”, MyNetworkReachabilityListener )
else
native.showAlert(“network”, “not supported”, {“OK”})
print(“network reachability not supported on this platform”)
end
end
end
[import]uid: 90878 topic_id: 20954 reply_id: 320954[/import]

I think network.canDetectNetworkStatusChanges is always false on Android. I don’t think we have a solution for this yet on Android.
[import]uid: 7563 topic_id: 20954 reply_id: 82835[/import]

Hi gregory,

I have the same problem. Perhaps you have found a solution for Android devices. I’ve so far found nothing.
Thanks for your help. [import]uid: 107610 topic_id: 20954 reply_id: 105270[/import]