我正在尝试使用Dropbox网址下载文件。我从“使用Android下载文件”中复制了代码,并在使用DownloadManager类的ProgressDialog中显示了进度。
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;
}
它正在努力实现带有URL的直接文件,但是这一次我试图使用Dropbox共享链接来实现它,但无法正常工作。我不想连接到Dropbox API。我认为这没用。有什么方法可以直接从Dropbox网址下载文件?
只需更换
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);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句