aide打开html文件,求助!aide获取网页html源码

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

package com.mycompany.myapp;

import android.app.*;

import android.content.*;

import android.os.*;

import android.widget.*;

import java.io.*;

import org.apache.http.*;

import org.apache.http.client.*;

import org.apache.http.client.methods.*;

import org.apache.http.impl.client.*;

public class MainActivity extends Activity

{

private TextView zf;

@Override

protected void onCreate(Bundle savedInstanceState)

{

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

zf=(TextView)findViewById(R.id.zf);

connect();

}

private void connect()

{

PageTask task = new PageTask(this);

//task.execute(url.getText().toString());

task.execute("http://www.android-doc.com");

}

class PageTask extends AsyncTask

{

ProgressDialog pdialog;

public PageTask(Context context)

{

pdialog = new ProgressDialog(context, 0);

new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int which)

{

// TODO Auto-generated method stub

}

};

pdialog.setOnCancelListener(new DialogInterface.OnCancelListener() {

@Override

public void onCancel(DialogInterface dialog)

{

dialog.cancel();

}

});

pdialog.setCancelable(true);

pdialog.setMax(100);

pdialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);

pdialog.show();

}

@Override

protected String doInBackground(String... params)

{

// TODO Auto-generated method stub

try

{

HttpClient client = new DefaultHttpClient();

HttpGet get = new HttpGet(params[0]);

HttpResponse response = client.execute(get);

HttpEntity entity = response.getEntity();

long length = entity.getContentLength();

InputStream is = entity.getContent();

String s = null;

if (is != null)

{

ByteArrayOutputStream baos = new ByteArrayOutputStream();

byte[] buf = new byte[128];

int ch = -1;

int count = 0;

while ((ch = is.read(buf)) != -1)

{

baos.write(buf, 0, ch);

count += ch;

if (length > 0)

{

publishProgress((int)((count / (float)length) * 100));

}

Thread.sleep(100);

}

s = new String(baos.toByteArray());

return s;

}

}

catch (Exception e)

{

// TODO: handle exception

e.printStackTrace();

}

return null;

}

@Override

protected void onCancelled()

{

super.onCancelled();

}

@Override

protected void onPostExecute(String result)

{

//result为获取到的源码

Toast.makeText(MainActivity.this, result, 0).show();

pdialog.dismiss();

zf.setText(result);

}

@Override

protected void onPreExecute()

{

}

@Override

protected void onProgressUpdate(Integer... values)

{

System.out.println("" + values[0]);

pdialog.setProgress(values[0]);

}}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值