您好我想下载视频文件,下面是我的代码
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);
}
在下载管理器中我获得了以下信息
如果我传递简单的网址,例如" http://beta-vidizmo.com/hilton.mp4"那它工作正常
答案 0 :(得分:4)
请尝试这种方式,希望这有助于您解决问题。
file_download("http://songs7.funmaza.in/videos/Issey Kehte Hain Hip Hop 720p - Yo Yo Honey Singh [Funmaza.com].wmv",context);
public void file_download(String url,Context context) {
url = url.replace(" ","%20");
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)
.setTitle("Demo")
.setDescription("Downloading via Your app name..")
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
.setDestinationInExternalPublicDir(Environment.getExternalStorageDirectory() + "/MyFolder", "test1.3gp");
downloadManager.enqueue(request);
}
答案 1 :(得分:1)
最后尝试并错误,我找到了这个解决方案,
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给你