Click here to Skip to main content
14,603,212 members
Rate this:
Please Sign up or sign in to vote.
See more:
         Intent intent = new Intent();
       intent = getIntent();

       contactUri = intent.getData();
Uri src_uri = Uri.parse(contactUri.getPath());
   Uri dst_uri = Uri.parse("file:///mnt/sdcard/download/testing.pdf");
   DownloadManager.Request req = new DownloadManager.Request(src_uri);
   req.setDestinationUri(dst_uri);
   DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
   dm.enqueue(req);

or
dmr.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName);
dmr.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
 dmr.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
 DownloadManager manager = (DownloadManager) mContext.getSystemService(Context.DOWNLOAD_SERVICE);
 manager.enqueue(dmr);


What I have tried:

i want to get the path of downloaded file or set it manually. Using above code will suddenly stop my app. I have include permisions in manifest also.
Posted
Updated 23-Jul-20 23:16pm
Comments
David Crow 21-Jul-20 8:59am
   
"Using above code will suddenly stop my app."

Where? Is an exception being thrown? Have you stepped through the code using the debugger?

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Looks to me that you're calling your download manager in the wrong place.


Intent intent = new Intent();
       
intent = getIntent();

       
contactUri = intent.getData();
Uri src_uri = Uri.parse(contactUri.getPath()); 
Uri dst_uri = Uri.parse("file:///mnt/sdcard/download/testing.pdf");  
DownloadManager.Request req = new DownloadManager.Request(src_uri);
req.setDestinationUri(dst_uri);
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
dm.enqueue(req);



try this:
Intent intent = new Intent();
intent = getIntent();

       contactUri = intent.getData();
Uri src_uri = Uri.parse(contactUri.getPath());
   Uri dst_uri = Uri.parse("file:///mnt/sdcard/download/testing.pdf");
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
DownloadManager.Request req = new DownloadManager.Request(src_uri);
req.setDestinationUri(dst_uri);
dm.enqueue(req);
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100