我从这里找到了这段代码下载 html 源代码 android? . 但是当我尝试运行它时,我的程序不断崩溃。我已经添加了互联网权限。有什么想法吗?
编辑:这是完整的错误消息。08-02 00:16:47.364:E/EmbeddedLogger(1577):获取包标签时出错:com.jimmyc.lawrenceh.schedulinglookup
Edit2:它适用于 Android 2.2,但不适用于 Android 4.0/3.0。
private void initialize() {
//initialize variables here
try {
getHtml();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void getHtml() throws ClientProtocolException, IOException {
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpGet httpGet = new HttpGet("http://www.yahoo.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";
// Toast.makeText(Connect.this, line.toString(), Toast.LENGTH_LONG).show();
}
}