Reputation: 6238
I can't really find by googling or searching stack what I should do for this: Our app is a tool to browse content generated through the API or on a website, in this content we have different files:
For images and video's we're displaying an viewer to display them. However for documents we would like the system itself to handle the file, therefore we'd like them to be downloaded like downloads from the browser.
Any idea's how I should handle such a request from android? All the files are just given by URL. I guess it should be easy but I can't really see how now.
Edit: Just for people who might be adding the wrong search words to google aswell this is all I needed:
//getting the download manager, my globalVars.context is added in the activity this is in a static function since I need this same code like 10 times in my app
dm = (DownloadManager) ((Activity) GlobalVars.context).getSystemService(GlobalVars.context.DOWNLOAD_SERVICE);
//set the request by an url from string to URI
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
//add this line to keep the notification after downloading, more options at: http://developer.android.com/reference/android/app/DownloadManager.Request.html request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
//execute the download request
enqueue = dm.enqueue(request);
Upvotes: 0
Views: 192
Reputation: 3188
You can access the DownloadManager
by calling getSystemService(DOWNLOAD_SERVICE);
and it will handle the download in background for you once you set it up. The references for getSystemService and DownloadManager
Upvotes: 1