Can png download and save on native platform happen only through hot update?

hi,
i want to download a png file into my installed app and save it there(not necessarily in the app installation folder…i don’t care where the file is saved as long it is on the device). now, i want to know if the following is the process for doing that:

  1. we need to use hot update.
  2. an older version of the file should already be present in the app.
  3. we need to unzip the earlier version of the apk and locate the png in the raw-assets folder(this step is too painstakingly long and time-consuming).
  4. we then need to upload a newer version of the png to our server.
  5. if the server entry of the png in the assets manifest is greater than the client entry then download the file.
  6. restart the app.

what is problematic here is that an older version of the file needs to be present already in the apk(a new file can’t be downloaded). also it is very time-consuming to locate the file in the raw-assets folder.

now, alternately, i can successfully download a png using cc.loader.load , but i am unable to save the file on the device using jsb.saveImageData.

can someone please tell me what the correct way to download and save a png is? and could you please provide a working example if possible?

Thank you!

As you said, you don’t care where it saved, so you just use cc.loader.load to load the png file, and if you have loaded it before, it will load from local cache.

hi,
cc.loader.load loads the image from the cache but the cache gets emptied after a session and in the next session the app has to download the pngs again. is there a way that the pngs can be saved on the device permanently?
i have another question…on the simulator i can do

jsb.saveImageData(texture._image._data, texture.width, texture.height, filepath);
where texture is obtained from cc.loader.load.

and i can use all the jsb.fileUtils methods…but on android platform they don’t seem to work. how can i check on a native platform, using jsb.fileUtils, whether a directory and a file exists or don’t exist? also, on the simulator, texture._image._data contain the data(typed array, i think) that need to go into jsb.saveImageData. on a native platform, where in texture is the data that is supposed to go into jsb.saveImageData ???

can you please provide a working example as that will be very helpful.

thank you!

Which cocos creator version are you using?

Versio : 2.3.3

in the simuator when i try to print values of texture._image._data[4widthy+4*x], i will get the red component of the png at coordinates x,y.
however in native when i tried to print the color value from texture._image._data i got the error message “ERROR: Uncaught TypeError: Cannot read property ‘121520’ of null”. also it didn’t save the image using jsb.saveImageData. can you tell me what is going on?
thank you!

Hi, it is a demo that use jsb.Downloader.
NewProject_4.zip (291.3 KB)

it worked…thank you very much!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.