Post Reply

[Q] Android DownloadManager issue

OP ArnoldasM

10th May 2014, 05:56 PM   |  #1  
OP Junior Member
Thanks Meter: 0
 
4 posts
Join Date:Joined: May 2014
Hello everyone,
for the last few days i'm messing around with DownloadManager in my app. It kinda works, but have some issues. It downloads file fine, but when I try to open file, it say "Can't open file". Here is download manager code from my app:

Code:
          Uri source = Uri.parse(url);
                DownloadManager.Request request = new DownloadManager.Request(
                        source);

                //Set title and get name file download
                //Replace %20 from filename with spaces
                request.setDescription("Downloading...");
                String split[] = url.split("/");
                String filename1 = split[split.length - 1];
                String filename2 = filename1.replace("%20", " ");
                request.setTitle(filename2);

                //Set path for save download file
                request.setDestinationInExternalPublicDir(
                        Environment.DIRECTORY_DOWNLOADS, filename2);

                //Show notification in notification bar after download
                request.setNotificationVisibility(
                        DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);

                DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
                manager.enqueue(request);
Thath everyone would understand easier, here is some screenshots with the issue:


As you can see, it downloads file:


File is downloaded successfully:


However, when I enter "Downloads" it still shows, that the file is still in "Downloading..." state. And when I try to open it, it says "Can't Open file"


And if I enter Downloads directory with "File Manager", I can see it has been completely downloaded, and If i try to open it, it opens just fine.
Maybe anyone knows how to fix it? or where should I look for an error?


P.S. Sorry if its not so clear, but English isn't my native language.

ArnoldasM
11th May 2014, 07:02 AM   |  #2  
Junior Member
Thanks Meter: 1
 
21 posts
Join Date:Joined: Feb 2012
Cool. What's the device? Android version?
11th May 2014, 07:36 AM   |  #3  
OP Junior Member
Thanks Meter: 0
 
4 posts
Join Date:Joined: May 2014
Quote:
Originally Posted by surlac

Cool. What's the device? Android version?

Nexus 4, CyanogenMod 11
11th May 2014, 10:12 PM   |  #4  
OP Junior Member
Thanks Meter: 0
 
4 posts
Join Date:Joined: May 2014
Nevermind. Found the issue... with status "Downloading...."


request.setDescription..... stupid me....



and if someone facess "Cant open file", you have to set mime type.
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Top Threads in Java for Android App Development by ThreadRank