Hi all,
I recently finished a contract to design and build a document viewing and form completion system on the iPad and Android systems.
The app works A-ok on the iPad and iOS in general; however, when I have come to test it upon my android device (Galaxy Tab) it doesn’t read the response from the web service (WS) correctly and, therefore, doesn’t populate the download screen correctly.
I have included files on what the WS response looks like and my code on decoding it.
Any help would be greatly appreciated cause I am completely baffled by this.
Also, I am running Corona Version 2012.840 (2012.06.19) just incase it helps.
function downloadIndex() a = 1 b = 1 c = 1 remove = 1 while remove \< 100 do if buttonIndex[remove]~=nil then buttonIndex[remove]:removeSelf() buttonIndex[remove] = nil end if controlIndex[remove] ~= nil then controlIndex[remove]:removeSelf() controlIndex[remove] = nil end if sectionsIndex[remove] ~= nil then sectionsIndex[remove]:removeSelf() sectionsIndex[remove] = nil end remove = remove + 1 end --network.download("URL", "GET", networkListener, "sectionsIndex.txt", system.TemporaryDirectory) --aPath = system.pathForFile("mainIndex.txt", system.documentsDirectory) print ("c - ", c) print("totalForms - ", totalForms) local function networkListener2( event ) local function fileDownloaded(event) controlIndex[buttonPressed].onRelease = nil end decodedResponse = {} eventResponseString = tostring(event.response) print("event.response", event.response) content = event.response decodedResponse = json.decode(eventResponseString) if ( event.isError ) then print( "Network error!") print("event.isError", event.isError) eventTextbox = native.newTextBox( 50, 100, 350, 100 ) eventTextbox.text = eventResponseString for key, value in pairs(decodedResponse["errors"]) do print("value: ", value) currentSection = value eventTextbox.text = ("Errors: ".. value) end else --eventTextbox1 = native.newTextBox(50, 300, 500, 200) for key, value in pairs(decodedResponse["records"]) do print("value: ", value) currentSection = value print("currentSection", currentSection["Description"]) formName = currentSection["Description"] loginKey = value end downloadedIndexArray = {} downloadedIndexWrite = system.pathForFile("downloadedIndex.json", system.DocumentsDirectory) s = io.open(downloadedIndexWrite, "r") if s == nil then s = io.open(downloadedIndexWrite, "w") s:write('{"records":[{"downloadedRecords":[{"downloadedForm1":{"form":"Getting Started.json","savedForms":{"form1":"Getting Started.json"},"formName":"Getting Started"}}]}]}') end s:close() downloadedIndexArray = {} downloadedIndexWrite = system.pathForFile("downloadedIndex.json", system.DocumentsDirectory) s = io.open(downloadedIndexWrite, "r") downloadedIndexArray = s:read ("\*a") s:close() jsonFile = json.decode(downloadedIndexArray) downloadedRecords = jsonFile["records"][1] if downloadedRecords["downloadedRecords"] ~= nil then for key, value in pairs(downloadedRecords["downloadedRecords"]) do currentSelection = value local i = 1 local downloadedBefore = false while i \< 30 do if currentSelection["downloadedForm"..i] ~= nil then for k, v in pairs(currentSelection["downloadedForm"..i]) do print(k,v) end print("currentSelection[downloadedForm"..i.."].form", currentSelection["downloadedForm"..i].form) if currentSelection["downloadedForm"..i].form == formName then local alertbox = native.showAlert("Already downloaded", "You have already downloaded this form. If this is a new version of the form, please delete the previous form and try again", {"Ok"}) downloadedBefore = true end end i = i + 1 end print("downloadedBefore", downloadedBefore) if downloadedBefore == false then local d = 1 while d \< 30 do if currentSelection["downloadedForm"..d] == nil then currentSelection["downloadedForm"..d] = {} for k, v in pairs(currentSelection["downloadedForm"..d]) do print(k,v) end currentSelection["downloadedForm"..d].form = formName currentSelection["downloadedForm"..d].savedForms = {} currentSelection["downloadedForm"..d].savedForms.form1 = formName d = 50 end d = d + 1 end downloadedIndexWrite = system.pathForFile(formName..".json", system.DocumentsDirectory) s = io.open(downloadedIndexWrite, "r") if s == nil then s = io.open(downloadedIndexWrite, "w") s:write(content) end s:close() downloadedIndexArray = json.encode(jsonFile) downloadedIndexWrite = system.pathForFile("downloadedIndex.json", system.DocumentsDirectory) s = io.open(downloadedIndexWrite, "w") s:write(downloadedIndexArray) s:close() online = native.showAlert("File Downloaded", "File downloaded successfully", {"Ok"}, fileDownloaded) end end end end end function quickFormDL(event) buttonPressed = event.target.id print("buttonPressed", buttonPressed) network.request(settingsIndex.downloadURL..formList[event.target.id].questionnaireID, "GET", networkListener2, params ) end if totalForms == nil then local alertBox = native.showAlert("No forms", "There are no forms to download, Please create some so they can be downloaded", {"Ok"}) else totalNumberOfButtons = 0 while b \<= totalForms do print("formList["..b.."]", formList[b]) if formList[b] ~= nil then totalNumberOfButtons = totalNumberOfButtons + 1 print("formList["..b.."].questionnaireID", formList[b].questionnaireID) controlIndex[b] = widget.newButton { id = formList[b].questionnaireID, label = formList[b].description, fontSize = settingsIndex.fontSize, width = ((display.contentWidth/3)\*2)-60, height = 70, top = (totalNumberOfButtons\*70)-50, left = 700, onRelease = quickFormDL, cornerRadius = 3, emboss = true, defaultColor = {247,247,247,222}, overColor = {49,79,250,231} } transition.to(controlIndex[b], {time=300, x=(display.contentWidth-((display.contentWidth/3)))}) end b = b + 1 end end end
{"errors":[],"records":[{"Description":"Questionnaire One","QuestionnaireID":5,"Type":"Document"}],"success":true,"totalRecords":1}

