问题:从链接下载文件 Android Java

huangapple go评论67阅读模式
英文:

Problem downloading files from link android java

问题

我有一个链接,如果我们访问它,.mp4 文件将会自动下载,但如果尝试使用下载管理器下载,则文件将以 .html 格式保存,我想要的是 .mp4 格式。

String ID = "https://presaver.com/download/9Tw-f3i-08k/22";
DownloadManager downloadmanager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
Uri uri = Uri.parse(ID);
DownloadManager.Request request = new DownloadManager.Request(uri);
request.setTitle("YoutubeVideo");
request.setDescription("下载 YouTube 视频");
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setVisibleInDownloadsUi(true);
request.setDestinationUri(Uri.parse(path));
downloadmanager.enqueue(request);


<details>
<summary>英文:</summary>

I have a link where if we go, the .mp4 file will be downloaded automatically, but if the try to do using the download manager then the files is saved as .html format which I want in .mp4.

String ID = "https://presaver.com/download/9Tw-f3i-08k/22";
DownloadManager downloadmanager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
Uri uri = Uri.parse("ID");
DownloadManager.Request request = new DownloadManager.Request(uri);
request.setTitle("YoutubeVideo");
request.setDescription("Downloading youtube video");
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setVisibleInDownloadsUi(true);
request.setDestinationUri(Uri.parse(path));
downloadmanager.enqueue(request);


</details>


# 答案1
**得分**: 1

我认为您在这行代码中写错了:

```java
Uri uri = Uri.parse("ID");

应该改为:

Uri uri = Uri.parse(ID); // 字符串 ID
英文:

I think you miswrote this line

Uri uri = Uri.parse(&quot;ID&quot;);

It should be

Uri uri = Uri.parse(ID); // string ID

huangapple
  • 本文由 发表于 2020年10月9日 01:21:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/64267645.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定