Network requests not working with Android

Hi!

So I have this code, in which the app makes multiple requests at once, and for some reason so of the requests don’t return an image when testing on a device. It works fine on mac simulator and iPhone, but when I put it on an android device then it doesn’t work.

Here’s my code:

  
function getFruits( event )  
 print("Downloading items")  
 local newData = {}  
 local goodData = {}  
 local badData = {}  
 local downloadImages  
 local function loginCallback(event)  
  
 if ( event.isError ) then  
 print( "Network error!")  
 elseif event.response ~= nil then  
 print("Item Response: "..event.response..", Status: ".. event.status)  
 local data = json.decode(event.response)  
  
 for i = 1, #data do  
 if data[i][3] == "good" then  
 goodData[#goodData+1] = data[i]  
  
 elseif data[i][3] == "bad" then  
 badData[#badData+1] = data[i]  
 end  
 end  
 for i = 1, #goodData do  
 newData[i] = {}  
 newData[i].value = goodData[i][2]  
 newData[i].importance = goodData[i][4]  
 end  
 foodList[1] = newData  
 foodList[2] = #badData  
 saveFile("foodList.txt", json.encode(foodList))  
  
 downloadImages()  
 end  
 end  
  
 if internetConnection() == true then  
 network.request( "http://deleurapps.com/downloadFruits.php?type=data", "GET", loginCallback )  
 end  
 function downloadImages()  
  
 function networkImageListeners( event )  
 print("Item Image Response: "..event.response..", Status: ".. event.status)  
 return true  
 end  
  
 if #newData \> 0 then  
 for i = #newData+1, 10 do   
 if system.pathForFile( "foodGood\_"..i..".png", system.DocumentsDirectory ) ~= nil then  
 os.remove( system.pathForFile( "foodGood\_"..i..".png", system.DocumentsDirectory ) )  
 end  
 end  
 for i = 1, #newData do  
 network.download(  
 "http://deleurapps.com/downloadFruits.php?id="..i.."&type=image&state=good",  
 "GET",  
 networkImageListeners,  
 "foodGood\_"..i..".png",  
 system.DocumentsDirectory )  
 end  
 end  
 if #badData \> 0 then  
 for i = #badData+1, 10 do   
 if system.pathForFile( "foodBad\_"..i..".png", system.DocumentsDirectory ) ~= nil then  
 os.remove( system.pathForFile( "foodBad\_"..i..".png", system.DocumentsDirectory ) )  
 end  
 end  
 for i = 1, #badData do  
 network.download(  
 "http://deleurapps.com/downloadFruits.php?id="..i.."&type=image&state=bad",  
 "GET",  
 networkImageListeners,  
 "foodBad\_"..i..".png",  
 system.DocumentsDirectory )  
 end  
 end  
 end  
  
  
end  
getFruits()  
  

Thanks! [import]uid: 130035 topic_id: 32161 reply_id: 332161[/import]