- Home /
Download Image to a new album (Android)
I have a button that saves an image from URL to the device, and then opens it. I want all the images to save in a new abloum which will be created when pressing the button. current code is:
using UnityEngine;
using System.Collections;
public class OnPressingPictureButton : MonoBehaviour {
public int currentPage;
public string [] imageURL;
public Book book;
// Update is called once per frame
void Update () {
currentPage = book.page;
}
void OnMouseDown ()
{
StartCoroutine (TestDownload (imageURL[currentPage]));
}
private IEnumerator TestDownload (string uRL)
{
#if UNITY_ANDROID
WWW www = new WWW (uRL);
yield return www;
while (!www.isDone) {
Debug.Log (www.progress);
yield return null;
}
string savePath = Application.persistentDataPath + "/image"+currentPage.ToString()+".jpg";
byte[] bytes = www.bytes;
System.IO.File.WriteAllBytes (savePath, bytes);
Application.OpenURL (savePath);
#endif
}
}
BTW this isn`t optimized (user downloads the image every time hitting the button instead of first, checking if the image exists, if yes- open it. if not-download it.)
thanks!
Comment