Hi all,
Right now I have it downloading a default .txt file with some text in it, that I would like to put into a native alert to let players know of my new games.
The .txt file is downloading properly, however, I was confused as to how to make it be read and put into the alert popup dialogue box.
For example, I have it downloading a title file to change the text in the alert’s title. However, I do not know how to make it actually place in the downloaded text into the title area.
Here’s my code:
local function networkListener( event ) if ( event.isError ) then print( "Network error - download failed" ) elseif ( event.phase == "began" ) then print( "Progress Phase: began" ) elseif ( event.phase == "ended" ) then print( "Displaying response file" ) local path = system.pathForFile( "title.txt", system.TemporaryDirectory ) local file = io.open( path, "r" ) for line in file:lines() do print( line ) end io.close( file ) file = nil end end local params = {} params.progress = true network.download( "http://www.my\_url.com/title.txt", "GET", networkListener, params, "title.txt", system.TemporaryDirectory ) local function onComplete( event ) if event.action == "clicked" then local i = event.index if i == 1 then -- Do nothing; dialog will simply dismiss elseif i == 2 then -- Open URL if "Learn More" (second button) was clicked system.openURL( "MY APP URL THAT WAS DOWNLOADED WILL GO HERE" ) end end end
local alert = native.showAlert( "MY DOWNLOADED TITLE HERE", "MY DOWNLOADED DESCRIPTION HERE", { "Later", "Learn More" }, onComplete )
I would also like to make it so that I can have three files download, 1 for the title, 1 for the description, and 1 for the link that is opened when pressing the button. Is the network download repeatable for multiple files?
Thanks.