简体   繁体   English

使用下载管理器 Android 下载失败 9

[英]Unsuccessful download with Download Manager Android 9

I am trying to download a file from the internet with DownloadManager on Android 9, but I only get unsuccessful download.我正在尝试使用 Android 9 上的 DownloadManager 从 Internet 下载文件,但我只下载不成功。 This is what I am testing:这是我正在测试的:

My Manifest permission:我的清单许可:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />

My code to download it:我的下载代码:

    private final String FILE_NAME = "SampleDownloadApp.apk";
    String apkUrl = "https://androidwave.com/source/apk/app-pagination-recyclerview.apk";

public void download(Context context) {
    DownloadManager dm = (DownloadManager)context.getSystemService(DOWNLOAD_SERVICE);
    Uri mUri = Uri.parse(apkUrl);
    DownloadManager.Request r = new DownloadManager.Request(mUri);
    r.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
    Uri uri = Uri.parse("file://" + context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).toString() + "/" + FILE_NAME_2);
    r.setDestinationUri(uri);
    dm.enqueue(r);
}

I have tried android: usesCleartextTraffic = "true" in the manifest but then nothing happens.我已经在清单中尝试过 android: usesCleartextTraffic = "true" 但什么也没发生。 I never get any errors neither in logcat nor in run.我在 logcat 和运行中都没有遇到任何错误。

I followed this tutorial: https://androidwave.com/download-and-install-apk-programmatically/我按照本教程进行操作: https://androidwave.com/download-and-install-apk-programmatically/

I have no idea what the problem may be, any solution?我不知道问题可能是什么,有什么解决办法吗?

Help with this!帮助解决这个问题!

there is something wrong with you URL tried following and its working您有问题 URL 尝试了以下操作及其工作

private final String FILE_NAME = "SampleDownloadApp.apk";
    String apkUrl = "https://d-10.winudf.com/b/APK/Y29tLm5lbW8udmlkbWF0ZV80MzUxMV9iOTJjMTFkZA?_fn=VmlkTWF0ZSBIRCBWaWRlbyBEb3dubG9hZGVyIExpdmUgVFZfdjQuMzUxMV9hcGtwdXJlLmNvbS5hcGs&_p=Y29tLm5lbW8udmlkbWF0ZQ&am=cCsiKSeBEin6IVuzn-Q2PA&at=1590661203&k=3c1a8eca32edf42751cb3f5fa102d0205ed0e1d3";

public void download(Context context) {
    DownloadManager dm = (DownloadManager)context.getSystemService(DOWNLOAD_SERVICE);
    Uri mUri = Uri.parse(apkUrl);
    DownloadManager.Request r = new DownloadManager.Request(mUri);
    r.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
    r.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, FILE_NAME);
    dm.enqueue(r);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM