使用保管箱下载文件 url android
downloading files using dropbox url android
我正在尝试使用保管箱 url 下载文件。我从 Download a file with Android, and showing the progress in a ProgressDialog 复制了一个使用 DownloadManager class.
的代码
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;
}
它正在使用 urls 获取直接文件,但这次我尝试使用 Dropbox 共享链接来实现,但没有成功。我不想连接到保管箱 api。我觉得没用。有什么方法可以直接从保管箱下载文件吗url?
请参阅此link了解如何从 Dropbox 下载共享文件
https://blogs.dropbox.com/developers/2013/08/programmatically-download-content-from-share-links/
只是替换
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);
我正在尝试使用保管箱 url 下载文件。我从 Download a file with Android, and showing the progress in a ProgressDialog 复制了一个使用 DownloadManager class.
的代码 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;
}
它正在使用 urls 获取直接文件,但这次我尝试使用 Dropbox 共享链接来实现,但没有成功。我不想连接到保管箱 api。我觉得没用。有什么方法可以直接从保管箱下载文件吗url?
请参阅此link了解如何从 Dropbox 下载共享文件
https://blogs.dropbox.com/developers/2013/08/programmatically-download-content-from-share-links/
只是替换
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);