下载管理器不起作用

编程入门 行业动态 更新时间:2024-10-11 15:18:47
本文介绍了下载管理器不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试开发显示视频的应用,您可以下载它 我正在使用Download Manager类,但没有用,也没有给我任何错误:(

这是我的下载管理器代码:

public void downloadFileFromUrl(String url, String fileName) { String filePath=Environment.getExternalStorageDirectory() + File.separator + "BlueNet"; File folder = new File(filePath); if (!folder.exists()) { folder.mkdirs(); } try { Uri downloadUri = Uri.parse(url); DownloadManager.Request request = new DownloadManager.Request(downloadUri); request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI); request.allowScanningByMediaScanner(); request.setDestinationInExternalPublicDir("/BlueNet/",fileName); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); request.setVisibleInDownloadsUi(true); DownloadManager downloadManager = (DownloadManager)getApplicationContext().getSystemService(DOWNLOAD_SERVICE); long id= downloadManager.enqueue(request); Toast.makeText(this, fileName, Toast.LENGTH_LONG).show(); Toast.makeText(this, filePath, Toast.LENGTH_LONG).show(); } catch (Exception ex){ Toast.makeText(this, ex.toString(), Toast.LENGTH_LONG).show(); } }

这就是我的称呼方式

downloadFileFromUrl(path, fileName);

其中:

路径:"192.168.1.5:8080/BlueNet_NMC/blue_elephant.mp4"

文件名:"blue_elephant.mp4"

并且我已经将此权限授予了清单

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

所以请帮忙

如我在评论中所述,DownloadManager仅处理以或开头的请求,如您所见 .

我不知道到底是什么问题,因为我缺少有关您服务器的信息,但是我认为这是一个常见问题,因此您应该避免在未提供该方案的情况下使用IP地址.

I'm trying to develop app that show videos and you can Download it i'm using Download Manager class but it didn't work, also it didn't give me any error :(

this is my download manager code:

public void downloadFileFromUrl(String url, String fileName) { String filePath=Environment.getExternalStorageDirectory() + File.separator + "BlueNet"; File folder = new File(filePath); if (!folder.exists()) { folder.mkdirs(); } try { Uri downloadUri = Uri.parse(url); DownloadManager.Request request = new DownloadManager.Request(downloadUri); request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI); request.allowScanningByMediaScanner(); request.setDestinationInExternalPublicDir("/BlueNet/",fileName); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); request.setVisibleInDownloadsUi(true); DownloadManager downloadManager = (DownloadManager)getApplicationContext().getSystemService(DOWNLOAD_SERVICE); long id= downloadManager.enqueue(request); Toast.makeText(this, fileName, Toast.LENGTH_LONG).show(); Toast.makeText(this, filePath, Toast.LENGTH_LONG).show(); } catch (Exception ex){ Toast.makeText(this, ex.toString(), Toast.LENGTH_LONG).show(); } }

and this is how I'm calling it

downloadFileFromUrl(path, fileName);

where:

path: "192.168.1.5:8080/BlueNet_NMC/blue_elephant.mp4"

filename: "blue_elephant.mp4"

and i already give this permissions to manifests

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

so please any help

解决方案

As I said in the comments, DownloadManager only handles requests starting with or as you can see in the docs.

I don't know exactly what's the problem because I lack information about your server, but I think it's a common issue, so you should avoid using an IP address without providing that scheme.

更多推荐

下载管理器不起作用

本文发布于:2023-11-27 15:38:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1638593.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:管理器   不起作用

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!