首页 > 解决方案 > 在 android 9 和 10 和 11 中下载不工作(崩溃)

问题描述

当我在 android 9、10 和 11 中尝试它时,这段代码没有运行,但它在 android 8 中运行,请帮助我/谢谢。当我在 android 9、10 和 11 中尝试时,此代码没有运行,但它在 android 8 中运行,请帮助我/谢谢。

LinearLayout download_64_f= (LinearLayout)findViewById(R.id.download_64);
download_64_f.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        String path="https://dl.dropboxusercontent.com/s/xxxxxxxx/64_a.mp3";
        file_download_64_f(path);
        download_64_f.setEnabled(false);
        download_64_f.setAlpha(.2f); // grey it out
    }
});

public void file_download_64_f(String uRl) {
    File direct = new File(Environment.getExternalStorageDirectory(), rootFolderR);

    if (!direct.exists()) {
        direct.mkdirs();
    }

    DownloadManager mgr = (DownloadManager) this.getSystemService(Context.DOWNLOAD_SERVICE);

    Uri downloadUri = Uri.parse(uRl);
    DownloadManager.Request request = new DownloadManager.Request(downloadUri);
    request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI
            | DownloadManager.Request.NETWORK_MOBILE)
            .setAllowedOverRoaming(false).setTitle("64")
            .setDescription("Downloading,Please Wait ...")
            .setDestinationInExternalPublicDir("path/file/", "64_a.mp4");
    mgr.enqueue(request);

}

标签: javaandroid

解决方案


推荐阅读