Click here to Skip to main content
15,885,855 members
Please Sign up or sign in to vote.
1.00/5 (1 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

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);
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900