Download Webview files into custom folder

Asked

Viewed 226 times

0

I want the files that are downloaded by my Webview app to be in a custom folder. Currently it is going to the folder "Downloads" and wanted it to be for a folder with the name of the app and that folder is created automatically.

wb.setDownloadListener(new DownloadListener() {

            @SuppressLint("InlinedApi") public void onDownloadStart(String url, String userAgent,
                                                                    String contentDisposition, String mimetype,
                                                                    long contentLength) {
                DownloadManager.Request request = new DownloadManager.Request(
                        Uri.parse(url));

                request.allowScanningByMediaScanner();
                final String filename = URLUtil.guessFileName(url, contentDisposition, mimetype);
                request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //Notify client once download is completed!
                request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename);
                DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
                dm.enqueue(request);
                Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); //This is important!
                intent.addCategory(Intent.CATEGORY_OPENABLE); //CATEGORY.OPENABLE
                intent.setType("*/*");//any application,any extension
                Toast.makeText(getApplicationContext(), "Baixando!", //To notify the Client that the file is being downloaded
                        Toast.LENGTH_LONG).show();

            }
        });

How do I do it in this code there?

1 answer

1


I guess that’s how it is:

change that:
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename);
for
request.setDestinationInExternalPublicDir(path,filename);

add:
File path = new File(Environment.getExternalStorageDirectory()+"/NomeDaPasta");
or
if(!path.exists()) path.mkdir();

something like that, look for the library io.FIle and on the methodsmkdir, exist() and isDirectory().

  • worked out! Thank you!

  • a good is to give a studied in the libraries of IO

  • gave it right, I’m very grateful.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.