ASP源码.NET源码PHP源码JSP源码JAVA源码DELPHI源码PB源码VC源码VB源码Android源码
当前位置:首页 >> 低调看直播体育app软件下载 >> Android开发 >> Android初级jrs看球网直播吧_低调看直播体育app软件下载_低调看体育直播XUtils实现“断点续传”下载

Android初级jrs看球网直播吧_低调看直播体育app软件下载_低调看体育直播XUtils实现“断点续传”下载

来源:网络整理     时间:2016-07-03     关键词:

本篇文章主要介绍了" Android初级jrs看球网直播吧_低调看直播体育app软件下载_低调看体育直播XUtils实现“断点续传”下载",主要涉及到方面的内容,对于Android开发感兴趣的同学可以参考一下: 对于“断电续传”,在任何开发中都显得很重要。xutils对此封装的很好了,可以很简单的实现很多下载功能,其中就包括“断点续传”主要代码如下:package co...

对于“断电续传”,在任何开发中都显得很重要。xutils对此封装的很好了,可以很简单的实现很多下载功能,其中就包括“断点续传”

主要代码如下:

package com.itydl.xutils;

import java.io.File;

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

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {

	private TextView tv_failure;
	private TextView tv_progress;
	private ProgressBar pb;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		tv_failure = (TextView) findViewById(R.id.tv_failure);
		tv_progress = (TextView) findViewById(R.id.tv_progress);
		pb = (ProgressBar) findViewById(R.id.pb);
	}

	public void click(View v){
		HttpUtils utils = new HttpUtils();
		String fileName = "QQPlayer.exe";
		//确定下载地址
		String path = "http://192.168.1.104:8080/" + fileName;
		utils.download(path, //下载地址
				"sdcard/QQPlayer.exe", //文件保存路径
				true,//是否支持断点续传
				true, new RequestCallBack() {

					//下载成功后调用
					@Override
					public void onSuccess(ResponseInfo arg0) {
						Toast.makeText(MainActivity.this, arg0.result.getPath(), 0).show();

					}

					//下载失败调用
					@Override
					public void onFailure(HttpException arg0, String arg1) {
						// TODO Auto-generated method stub
						tv_failure.setText(arg1);
					}

                                     //进度条显示下载进度,而且即使断网,点击下载按钮仍然在原来位置下载
					@Override
					public void onLoading(long total, long current,
							boolean isUploading) {
						// TODO Auto-generated method stub
						super.onLoading(total, current, isUploading);
						pb.setMax((int)total);
						pb.setProgress((int)current);
						tv_progress.setText(current * 100 / total + "%");
					}
				});
	}

}

以上就介绍了 Android初级jrs看球网直播吧_低调看直播体育app软件下载_低调看体育直播XUtils实现“断点续传”下载,包括了方面的内容,希望对Android开发有兴趣的朋友有所帮助。

本文网址链接:http://www.codes51.com/article/detail_2254647.html

相关图片

相关文章