嗨,我想下载视频文件,下面是我的代码
public void file_download(String uRl) {
File direct = new File(Constant.FOLDER_PATH);
try {
uRl = "http://songs7.funmaza.in/videos/"
+ URLEncoder
.encode("Issey Kehte Hain Hip Hop 720p - Yo Yo Honey Singh [Funmaza.com].wmv",
"UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("URL For Download == " + uRl);
if (!direct.exists()) {
direct.mkdirs();
}
DownloadManager mdDownloadManager = (DownloadManager) ((Activity) context)
.getSystemService(Context.DOWNLOAD_SERVICE);
DownloadManager.Request request = new DownloadManager.Request(
Uri.parse(uRl));
request.setDescription("Downloading via Your app name..");
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationUri(Uri.fromFile(direct));
mdDownloadManager.enqueue(request);
}
在下载管理器中,我得到了以下信息
如果我通过简单的URL,例如“ http://beta-vidizmo.com/hilton.mp4 ”,则它可以正常工作
终于尝试并出错,我找到了这个解决方案,
File direct = new File(Constant.FOLDER_PATH);
uRl = "http://songs7.funmaza.in/videos/Issey Kehte Hain Hip Hop 720p - Yo Yo Honey Singh [Funmaza.com].wmv";
uRl = uRl.replace(" ", "%20");
uRl = uRl.replace("[", "%5B");
uRl = uRl.replace("]", "%5D");
System.out.println("URL For Download == " + uRl);
if (!direct.exists()) {
direct.mkdirs();
}
DownloadManager downloadManager = (DownloadManager) ((Activity) context)
.getSystemService(Context.DOWNLOAD_SERVICE);
DownloadManager.Request request = new DownloadManager.Request(
Uri.parse(uRl));
request.setAllowedNetworkTypes(
DownloadManager.Request.NETWORK_WIFI
| DownloadManager.Request.NETWORK_MOBILE)
.setAllowedOverRoaming(false)
.setDescription("Downloading via Your app name..")
.setTitle("Issey Kehte Hain Hip Hop")
.setNotificationVisibility(
DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
.setDestinationInExternalPublicDir("/MoviesAndSongs",
"test1.mp4");
downloadManager.enqueue(request);
完成了:)也感谢Haresh
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句