我正在尝试开发显示视频的应用,您可以下载它 我正在使用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.
更多推荐
下载管理器不起作用
发布评论