使用dropbox url android下载文件

时间:2015-11-08 13:13:54

标签: android dropbox android-download-manager

大家好我想尝试使用dropbox url下载文件,我复制了Download a file with Android, and showing the progress in a ProgressDialog中使用DownloadManager类的代码。

    public void downloadFromDropBoxUrl(View view) {
        //verfying if the downloadmanager is available first.
        if (isDownloadManagerAvailable(getApplication())) {
            String url = "https://www.dropbox.com/s/m4z5u9qstxdtbc3/AllExams22.pdf?dl=0";
            DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
            request.setDescription("Some descrition");
            request.setTitle("Some title");
// in order for this if to run, you must use the android 3.2 to compile your app
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                request.allowScanningByMediaScanner();
                request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
            }
            request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "my-map.pdf");

// get download service and enqueue file
            DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
            manager.enqueue(request);
        }
    }
    public static boolean isDownloadManagerAvailable(Context context) {

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
            return true;
        }
        return false;
    }

它正在努力用网址实现直接文件,但这次我试图用Dropbox共享链接但它没有工作,我不想连接到Dropbox api我认为它无用是他们无论如何我可以直接下载文件来自Dropbox网址? 谢谢。

2 个答案:

答案 0 :(得分:2)

只需替换

String url = "https://www.dropbox.com/s/m4z5u9qstxdtbc3/AllExams22.pdf?dl=0";

由:

String url = "https://dl.dropboxusercontent.com/s/m4z5u9qstxdtbc3/AllExams22.pdf";    

然后:

final DownloadTask downloadTask = new DownloadTask(YourActivity.this);
downloadTask.execute(url);

答案 1 :(得分:1)

请参阅此链接,了解如何从Dropbox下载共享文件

https://blogs.dropbox.com/developers/2013/08/programmatically-download-content-from-share-links/