- Home /
DownloadManager
Hey we've built an app for the GearVR, but due to size limitations we need to have the app download the video files first, and these files are quite large so we'd like to give the user the ability to close the app and let DownloadManager download the files in the background rather than keeping the app open. But we've been struggling with getting any Download Manager code to work, but strangely we have been successful with Toast messages which are invoked using the same AndroidJavaObject code.
Can anyone give us a hint as to what we're doing wrong here?
currentActivity.Call ("runOnUiThread", new AndroidJavaRunnable (() => {
try {
AndroidJavaClass uriClass = new AndroidJavaClass ("android.net.Uri");
AndroidJavaObject uriObject = uriClass.CallStatic<AndroidJavaObject> ("parse", "http://website.com/video.mp4");
AndroidJavaObject request = new AndroidJavaObject ("android.app.DownloadManager$Request", uriObject);
AndroidJavaObject downloadManager = new AndroidJavaClass ("android.app.DownloadManager");
downloadManager = currentActivity.Call<AndroidJavaObject> ("getSystemService", "DOWNLOAD_SERVICE");
long downloadID = downloadManager.CallStatic<long> ("enqueue", request);
_text.GetComponent<UnityEngine.UI.Text>().text = downloadID.ToString();
} catch (System.Exception e) {
_text.GetComponent<UnityEngine.UI.Text>().text = e.ToString();
}
AndroidJavaObject toast = new AndroidJavaObject("android.widget.Toast",currentActivity);
toast.CallStatic<AndroidJavaObject>("makeText",currentActivity,"good",(1)).Call("show");
}));
}
Answer by Tom-Goethals · Oct 25, 2016 at 08:48 AM
Hi There,
made this work by changing:
"DOWNLOAD_SERVICE" to "download"
CallStatic ("enqueue", request); to Call("enqueue", request);
Have you made any progress on this script? i would really like a robust script that allow you to set the filename, path and get some feedback on the download progress.
Thx Tom
Your answer
Follow this Question
Related Questions
Android build - videoplayer - cannot read .mp4 file 1 Answer
[Crash] Unity with GearVR can crash after allowing permissions after first installation 1 Answer
[SOLVED] Non-VR Scene in a GearVR Project 2 Answers
Using URL as Source In Video Player on Portable VR 1 Answer
How to open a url in VR Browser from a Gear VR app? 1 Answer