xUtils测试案例

package com.gyarmy.threaddownload;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.net.HttpURLConnection;
import java.net.URL;

import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.HttpHandler;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;

import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity {
	private EditText down_url;
	private TextView downState;
	// private static String path ="http://192.168.1.100:8080/file.txt";
	private static String path;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		down_url = (EditText) findViewById(R.id.url_down);
		downState = (TextView) findViewById(R.id.downState);

	}

	// File file = new
	// File(Environment.getExternalStorageDirectory().getAbsoluteFile()+"/"+getFileName(path));

	public void get_file(View v) {
		path = down_url.getText().toString().trim();
		System.out.println(path);

		HttpUtils http = new HttpUtils();
		HttpHandler handler = http
				.download(
						path,
						Environment.getExternalStorageDirectory().getAbsoluteFile()+"/"+"11.zip", true, 
						true, 
						new RequestCallBack<File>() {

							@Override
							public void onStart() {
								downState.setText("conn...");
							}

							@Override
							public void onLoading(long total, long current,
									boolean isUploading) {
								downState.setText(current + "/" + total);
							}

							@Override
							public void onSuccess(
									ResponseInfo<File> responseInfo) {
								downState.setText("downloaded:"
										+ responseInfo.result.getPath());
							}

							@Override
							public void onFailure(HttpException error,
									String msg) {
								downState.setText(msg);
							}
						});

	}

}

原文链接: xUtils测试案例 版权所有,转载时请注明出处,违者必究。
注明出处格式:流沙团 ( https://gyarmy.com/post-130.html )

发表评论

0则评论给“xUtils测试案例”