设置 DownloadManager 的目标路径

问题描述 投票:0回答:2

我正在使用下面的代码,但不知道文件正在下载到哪里。给定路径中没有存储任何文件。代码中需要进行哪些更正。代码在开始时创建文件夹。

  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;
java android android-download-manager
2个回答
5
投票

简单使用

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

0
投票

这就是我解决问题的方法

request.setDestinationInExternalFilesDir(context, "/path/", "MyFile.txt");
© www.soinside.com 2019 - 2024. All rights reserved.