代码之家  ›  专栏  ›  技术社区  ›  Panache

设置DownloadManager的目标路径

  •  0
  • Panache  · 技术社区  · 8 年前

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

      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;
    
    1 回复  |  直到 8 年前
        1
  •  3
  •   Moien.Dev    8 年前

    简单使用

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