Network.download event listener problem

Hi all,

I am developing a simple app which will run on AndroidTV to show images and videos in a business centre. The images and videos will be downloaded through an API and saved to local.

However, I have problem with the network.download event listener on AndroidTV. Everything runs smoothly on a phone but on TV it does not work. After tens of times building and uploading to Google Play, and then updating on the TV and testing, I found out that the problem is somewhere in network.download event listener. When I check if event.isError, it does not give any error. When I print out the event.phase, it shows the “ended” phase, however, if I try to print out a text inside the “ended” phase, it does not show.

In the below code, globalData.itr is used for writing what it holds to the screen as I can not see the TV logs. On the screen it should write “downloaded” but it writes “equest network event listener phase ended”

Any idea what should I look for the fix this problem?

local function networkListener( event )
globalData.itr = "request network event listener phase "..event.phase
if ( event.isError ) then
    print( "Network error: " .. event.response )
elseif ( event.phase == "began" ) then
    print( "Progress Phase: began" )
elseif event.phase == "ended" then
    print ( "RESPONSE: File downloaded" )
    globalData.itr = "downloaded"
end
end

Hello. Maybe the update rate of the TextObject that is showing the globalData.itr string is not large enough for you to perceive every networkListener phase’s message, thus leaving you with the impression that the only phase it’s going through is “ended”. If this is what is happening, then your listener is working as expected and as it does on a phone, and the problem resides in another part of your program (saving to local, perhaps?).

@napolimatiase, thanks for the insight.

If I didn’t misunderstand, what you say is that the file saving process might be the problem, which occurs before “ended” event phase is received. In that case, shouldn’t it return “true” for the event.isError?

Until this event listener point, I have used globalData.itr string in different places and, so far, every one of them showed on the screen.

Inside the ended phase block I have some other checks where I set globalData.itr string. Is it possible that all those three times that strings are set are skipped?

  elseif event.phase == "ended" then
    print ( "RESPONSE: File downloaded" )
    globalData.itr = "downloaded"

    -- open the json file from the temporary folder
    local json = require( "json" )
    local filename = system.pathForFile( "content.json", system.TemporaryDirectory )
    local decoded, pos, msg = json.decodeFile( filename )
    globalData.itr = "opening ok"

    -- if decode failed, which means no or corrupted file, get from the remote
    if not decoded then
        print( "Decode failed at "..tostring(pos)..": "..tostring(msg) )
        globalData.itr = "Decode failed at "..tostring(pos)..": "..tostring(msg)
    else
        print( "File successfully decoded!" )
        globalData.content = decoded
    end
end

Actually i was refering more to where it’s being saved (and loaded) more than if it’s being succesfully downloaded (which we know it is since there’s no error msg).

The three times you set globalData.itr a value are taking place, not skipped, but any message will be shown if you don’t pass it to a TextObject’s text property (unless globalData.itr has a metatable set to do it automatically, or there’s a timer.performWithDelay calling some function that does it, somewhere in your code). Also, think that between assignments there’s an interval in the order of milliseconds, so you won’t be able to read every message, just the last one. You can apply a pause so you can read them, or append them in a TextBox object (console fashion).