你在网上找一下HTTP远程下载的看看。我写过一个。自动下APK文件的,我的没发现问题!

解决方案 »

  1.   

    HttpURLConnection 或者 HttpClient这些必须先要掌握的
      

  2.   

    URLConnection和HttpURLConnection 有什么区别呢?
    我是用URLConnection来搞的,
    不好用~
    我正在看httpclient~~~
      

  3.   


    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);
    }
    代码封装的太多,大体就这样你悟悟吧!呵可!
      

  4.   

    Uri packageUri = Uri.fromFile(file);
      

  5.   

    呵呵,谢谢了,从哪粘来到代码啊,容易误导啊。HttpURLConnection搞定了