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");


        }));
    }

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