- Home /
Downloaded Images using unity web request get automatically deleted in Android Devices
Hi Everyone,
I am developing a puzzle game using the Unity game engine for Android devices. The game has about 500+ Images or so, that is why the game has a dynamic system of fetching the puzzle data and images from the server and storing it in the local storage of the device at runtime. This works really well for now, but upon testing and user reports, we discovered that the images get deleted randomly out of nowhere on some devices. There is no system or code for deleting images in our game, so definitely it's nothing that the game is doing.
Two Images from a user for reference : Data before deletion : Data After Deletion
This is a consistent behaviour for some users, and some don't face it at all. Most of them have Android Q. The snippet of code I use to download the images and store them in the local storage.
using (UnityWebRequest request = UnityWebRequestTexture.GetTexture(link))
{
yield return request.SendWebRequest();
if (request.isNetworkError || request.isHttpError)
Debug.Log(request.error);
else
{
this.GetComponent<RawImage>().texture = ((DownloadHandlerTexture)request.downloadHandler).texture;
byte[] bytes = ((DownloadHandlerTexture)request.downloadHandler).data;
if (bytes.Length > 1)
{
File.WriteAllBytes(Application.persistentDataPath + "/.cache/" + ID, bytes);
isImageDownloaded = true;
}
request.downloadHandler.Dispose();
request.Dispose();
}
}
I am not sure about why these images get deleted. If anyone can help me trouble shoot this issue will be great.
I am sorry if I have broken any guidlines in this post, please let me know for correction.