下载管理器不工作 [英] Download Manager not working
问题描述
我正在尝试开发显示视频的应用程序,您可以下载它我正在使用下载管理器类,但它没有用,也没有给我任何错误:(
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 :(
这是我的下载管理器代码:
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"
path: "192.168.1.5:8080/BlueNet_NMC/blue_elephant.mp4"
文件名: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" />
所以请任何帮助
推荐答案
正如我在评论中所说的,DownloadManager
只处理以 http://
或 开头的请求代码>https://
如您所见 在文档中.
As I said in the comments, DownloadManager
only handles requests starting with http://
or https://
as you can see in the docs.
我不知道具体是什么问题,因为我缺少有关您服务器的信息,但我认为这是一个常见问题,因此您应该避免使用未提供该方案的 IP 地址.
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.
这篇关于下载管理器不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!