Android中,ucweb的下载是如何做到的? 你在网上找一下HTTP远程下载的看看。我写过一个。自动下APK文件的,我的没发现问题! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 HttpURLConnection 或者 HttpClient这些必须先要掌握的 URLConnection和HttpURLConnection 有什么区别呢?我是用URLConnection来搞的,不好用~我正在看httpclient~~~ 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); }代码封装的太多,大体就这样你悟悟吧!呵可! Uri packageUri = Uri.fromFile(file); 呵呵,谢谢了,从哪粘来到代码啊,容易误导啊。HttpURLConnection搞定了 HTC G14 官方升级4.0.3后,进行官方解锁 网站与手机客户端相结合的位置服务签到疑惑 android的R文件中,没有id是怎么回事啊? 关于aidl的问题??????? 关于HorizontalScrollView滚动后获取焦点的问题,谢谢 SDK开发范例大全第三版课后代码免费的谁有? ADT LogCat 里只显示W I E的信息 Android socket 问题 好郁闷的问题 volley使用错误 有谁用过HTC G3的进来看看~~~ 共享bug,求解
我是用URLConnection来搞的,
不好用~
我正在看httpclient~~~
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);
}
代码封装的太多,大体就这样你悟悟吧!呵可!