如何在android中下载页面

问题描述:

我正在开发一个android应用程序,其中的应用程序必须下载一个网页..如何代码必须write.if任何知道请帮助。如何在android中下载页面

我需要下载网页和查看在网页视图是this

我指这个question达到我的目的。但我ddn't得到正确的答案...

+0

我不知道,但看看它http://java-source.net/open-source/crawlers – Pragnani 2013-04-09 10:21:29

您可以使用口袋:

Click here.

下会有所帮助。
How to download a webpage for offline viewing on Nexus 7

您可以使用此示例代码下载html源代码。

public void getHtml() throws ClientProtocolException, IOException 
{ 
    HttpClient httpClient = new DefaultHttpClient(); 
    HttpContext localContext = new BasicHttpContext(); 
    HttpGet httpGet = new HttpGet("http://www.androidaspect.com/"); 
    HttpResponse response = httpClient.execute(httpGet, localContext); 
    String result = ""; 

    BufferedReader reader = new BufferedReader(
     new InputStreamReader(
      response.getEntity().getContent() 
     ) 
    ); 

    String line = null; 
    while ((line = reader.readLine()) != null){ 
     result += line + "\n"; 

    } 

} 

要对发售者用的AsyncTask,而不是在主线程中使用它。不要忘记为

<uses-permission android:name="android.permission.INTERNET"> 

权限。