java - 在 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);
}
解决方案
推荐阅读
- r - Automating the process of recoding numeric variables to meaningful factor variables
- python - Jenkins: How to display console output into a separate text file?
- laravel - Export Excel in Laravel
- python - If value is in this list and somewhere in a column's value can I replace that column value with list value? Pandas DataFrame
- c# - Asp net entity framework - migration generation
- javascript - Create a loop to compile multiple records into a new variable
- rust - 无法将内部值移出 Arc Rust
- sql - 使用 SQL 窗口函数更新下一行的值?
- python - 列表理解和三元运算符 -> SyntaxError
- javascript - 设置文本开始换行的视口宽度