我正在尝试从Dropbox下载文件。当我尝试下载此URL https://www.dropbox.com/s/zf68ylazusvpnga/Cir_IMG-10-20181025145334.jpg?raw=1 时,应用崩溃了,我收到此错误
java.lang.IllegalArgumentException: Can only download HTTP/HTTPS URIs: "https://www.dropbox.com/s/zf68ylazusvpnga/Cir_IMG-10-20181025145334.jpg?raw=1"
at android.app.DownloadManager$Request.<init>(DownloadManager.java:436)
at com.valai.school.adapter.ImageMessageViewHolder.downloadImageFile(ImageMessageViewHolder.java:140)
at com.valai.school.adapter.ImageMessageViewHolder.access$000(ImageMessageViewHolder.java:43)
at com.valai.school.adapter.ImageMessageViewHolder$2.onClick(ImageMessageViewHolder.java:124)
at android.view.View.performClick(View.java:4856)
at android.view.View$PerformClick.run(View.java:19956)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:211)
at android.app.ActivityThread.main(ActivityThread.java:5371)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:945)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:740)
这是我的代码:
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(message.getAttachmentURL().trim()));
request.setAllowedNetworkTypes(
DownloadManager.Request.NETWORK_WIFI
| DownloadManager.Request.NETWORK_MOBILE)
.setAllowedOverRoaming(false);
request.setDestinationInExternalFilesDir(context, imageFolderPath, fileName);
final DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
final long downloadId = manager.enqueue(request);
答案 0 :(得分:0)
String url = "https://www.dropbox.com/s/zf68ylazusvpnga/Cir_IMG-10-
20181025145334.jpg?raw=1";
DownloadManager.Request request = new
DownloadManager.Request(Uri.parse(url.trim()));
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI
| DownloadManager.Request.NETWORK_MOBILE).setAllowedOverRoaming(false);
request.setDestinationInExternalFilesDir(this, "/images", "sample");
final DownloadManager manager =
(DownloadManager)getSystemService(Context.DOWNLOAD_SERVICE);
final long downloadId = manager.enqueue(request);
Log.d(SO, " download id " + downloadId);`
为我工作。