设置下载管理器的目标路径



i m使用以下代码,但不知道文件在哪里下载。没有存储在给定路径的文件。代码需要什么更正。代码在开始时创建文件夹。

  String path = Environment.getExternalStorageDirectory().getPath() + "/Myapp/Videos";
        System.out.println(path);
        File folder = new File(path);
        if (folder.canExecute()) {
            System.out.println("Video  Folder Found");
        } else {
            folder.mkdirs();
        }
        DownloadManager.Request request = new DownloadManager.Request(uri);
        request.setDescription("Selected Video is being downloaded");
        request.allowScanningByMediaScanner();
        request.setTitle("Downloading Video");
        request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
        request.setDestinationInExternalFilesDir(mContext, null, title + ".mp4");
        DownloadManager manager = (DownloadManager) mContext.getSystemService(Context.DOWNLOAD_SERVICE);
        manager.enqueue(request);
        return null;

只需使用

request.setDestinationInExternalPublicDir("/Path", "test.mp4");

这就是我解决问题的方式

request.setDestinationinexternalFilesdir(上下文,"/path/"," myfile.txt"); 

最新更新