Android中,ucweb的下载是如何做到的?

程序员Linc
优质创作者: 人工智能技术领域
领域专家: 操作系统技术领域
2010-09-21 12:08:52
最近在做一个下载的小程序,在真机上跑起来,感觉不但下载速度慢,而且最要命的是文件下载下来有错误!
用ucweb下载,不但速度快,下载的文件还是完整的。

请大侠帮忙指导下,android里面如何写下载程序呢?
有没有例子?
我在网上找了好久,资料并不多。。。
...全文
133 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
程序员Linc 2010-09-25
  • 打赏
  • 举报
回复
呵呵,谢谢了,从哪粘来到代码啊,容易误导啊。

HttpURLConnection搞定了。。。

SongQues 2010-09-21
  • 打赏
  • 举报
回复
Uri packageUri = Uri.fromFile(file);
SongQues 2010-09-21
  • 打赏
  • 举报
回复

public void getDownloadFile() {
if (DEBUG)
NLog.i(Tag, "xuezhg CM_POSTREQUEST_REGISTER begin......");
String sendURL = ReaderPreferences.getUpdateUrl();
if (sendURL == null) {
Log.e(Tag, "send URL is null!");
processsDialog.dismiss();
// ophone start modfy by wangjd 2010.06.03 for Neu0000878
// Toast.makeText(this, "升级失败,请稍后重试...", Toast.LENGTH_SHORT).show();
Toast.makeText(this, R.string.update_failed, Toast.LENGTH_SHORT)
.show();
// end for Neu0000878
mHandler.sendEmptyMessageDelayed(0, 1000);
return;
}
Log.e(Tag, "URL : " + sendURL);
URL url = null;
try {
url = new URL(sendURL);
} catch (Exception e) {
Log.e(Tag, sendURL + " is not a URL");
}
String proxy = "10.0.0.172";
String port = "80";
Log.e(Tag, "Auth : " + proxy + ":" + port);

Properties systemProperties = System.getProperties();
systemProperties.setProperty("http.proxyHost", proxy);
systemProperties.setProperty("http.proxyPort", port);

HttpURLConnection conn = null;

try {
conn = (HttpURLConnection) url.openConnection();
Log.e(Tag, "response code : " + conn.getResponseCode());
Log.e(Tag, "URL is : " + conn.getURL().toString());
sendURL = conn.getURL().toString();
} catch (Exception e) {
Log.e(Tag, "get connecntion error");
}
try {
Log.e(Tag, ((HttpURLConnection) url.openConnection()).getURL()
.toString());
} catch (Exception e) {
Log.e(Tag, "openURL error: " + e.toString());
}
// filename = CM_Utility.getImagePath() +
// CM_Utility.getImageName(sendURL);
filename = CM_Utility.getBookPath() + CM_Utility.getImageName(sendURL);
CM_Utility.sendCommand(CM_CommandDef.CM_DOWNLOAD_START, sendURL,
CM_ActivityList.LOADING);
// CM_Utility.Update(CM_MessageDef.CM_GET_DOWNLOAD, sendURL, 0, 0,
// CM_ActivityList.LOADING);

if (DEBUG)
NLog.i(Tag, "xuezhg sendURL: " + sendURL);
if (DEBUG)
NLog.i(Tag, "xuezhg filename: " + filename);
}


代码封装的太多,大体就这样你悟悟吧!呵可!
程序员Linc 2010-09-21
  • 打赏
  • 举报
回复
URLConnection和HttpURLConnection 有什么区别呢?
我是用URLConnection来搞的,
不好用~


我正在看httpclient~~~
andyweike 2010-09-21
  • 打赏
  • 举报
回复
HttpURLConnection 或者 HttpClient这些必须先要掌握的
f8376904110 2010-09-21
  • 打赏
  • 举报
回复
你在网上找一下HTTP远程下载的看看。我写过一个。自动下APK文件的,我的没发现问题!
程序员Linc 2010-09-21
  • 打赏
  • 举报
回复
求助啊,大侠们~~

80,488

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧