android82 文件下载框架xUtils

package com.itheima.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 {//xUtils-2.6.14.jar
    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.13.13:8080/" + fileName;
        utils.download(path, //下载地址
                "sdcard/QQPlayer.exe", //文件保存路径
                true,//是否支持断点续传
                true, //是否支持重命名
                new RequestCallBack<File>() {
                    //下载成功后调用
                    @Override
                    public void onSuccess(ResponseInfo<File> 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 + "%");
                    }
                });
    }
}
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
时间: 2024-12-07 06:51:59

android82 文件下载框架xUtils的相关文章

开源Http文件下载框架file-downloader的使用

file-downloader(https://github.com/wlfcolin/file-downloader)是本人开源的一个Http文件下载框架,是根据自己的经验总结的一套简非常轻量级的安卓通用Http文件下载管理器. 特点:支持断点续传.多任务下载.重命名.移动.删除.自定义下载名称和保存路径等 file-downloader采用了跟安卓图片加载框架image-loader类似的设计架构,以下是使用说明和截图: 1.在你的Application的onCreate()方法中初始化Fi

android 开源框架xUtils

首先查到的博客地址:  http://zxs19861202.iteye.com/blog/2003241 Github地址: https://github.com/wyouflf/xUtils xUtils简介 xUtils 包含了很多实用的android工具. xUtils 最初源于Afinal框架,进行了大量重构,使得xUtils支持大文件上传,更全面的http请求协议支持(10种谓词),拥有更加灵活的ORM,更多的事件注解支持且不受混淆影响... xUitls最低兼容android 2.

Android最近项目用到的框架xUtils

项目地址:https://github.com/wyouflf/xUtilsxUtils 简介 xUtils 包含了很多实用的android工具. xUtils 源于Afinal框架,对Afinal进行了大量重构,使得xUtils支持大文件上传,更全面的http请求协议支持,拥有更加灵活的ORM,更多的事件注解支持且不受混淆影响... xUitls最低兼容android 2.2 (api level 8) DbUtils模块: android中的orm框架,一行代码就可以进行增删改查: 支持事务

Android 最火框架XUtils之注解机制具体解释

在上一篇文章Android 最火的高速开发框架XUtils中简介了xUtils的基本用法,这篇文章说一下xUtils里面的注解原理. 先来看一下xUtils里面demo的代码: @ViewInject(R.id.tabhost) private FragmentTabHost mTabHost; @ViewInject(R.id.big_img) private ImageView bigImage; 可能好多人一看就说这是个what,事实上这是Java core里面的内容,做JavaEE的应该

Android orm 框架xUtils简介

数据库操作建议用ORM框架,简单高效.这里推荐xUtils,里面包含DBUtils.github地址:https://github.com/wyouflf/xUtils 获得数据库实例建议用单例模式. static DbUtils db = null; public static DbUtils getDb(Context context) { if (context == null) { context = DoctorApplication.getInstance(); } if (db =

Android高级_第三方框架Xutils

xutils的功能主要包括有四个部分:(1)布局视图关联:(2)图片下载与缓存:(3)网络请求:(4)数据库: 1. 使用xutils进行视图注入: (1)在控件声明上方添加@ViewInject()传入控件的资源Id: (2)OnCreate()中使用x.view().inject(),传入上下文对象即可: (3)设值点击事件: (3-1)自定义点击事件方法:访问权限为私有private void,传入View参数: (3-2)在方法上方加入注解@Event()传入控件的资源Id: 注意:如果

安卓系统下的多线程断点下载实现2利用开源框架XUtils

使用开源框架可以大大降低开发的难度,减少开发的周期,并且bug也少的多,软件运行起来更稳定. xUtils简介 xUtils 包含了很多实用的android工具. xUtils 支持大文件上传,更全面的http请求协议支持(10种谓词),拥有更加灵活的ORM,更多的事件注解支持且不受混淆影响- xUitls 最低兼容android 2.2 (api level 8) 下载地址:https://github.com/wyouflf/xUtils 下面是一个demo: public class Ma

[Android] 开源框架 xUtils HttpUtils 代理设置 (Temporary Redirect错误)

今天简单学习了一下xUtils的使用 https://github.com/wyouflf/xUtils 其中用到HttpUtils模块时,发现总是出现Temporary Redirect 错误. 查看源代码,发现如果是通过代理上网的话,需要在初始化HttpUtils时,传代理的String值. 在HttpUtils.java中: public HttpUtils(int connTimeout, String userAgent) { HttpParams params = new Basic

安卓 开源框架xUtils

http://www.tuicool.com/articles/jQnMRjB https://github.com/wyouflf/xUtils3/tree/master http://blog.csdn.net/dj0379/article/details/38356773/ http://www.jb51.net/article/89784.htm http://www.jb51.net/article/98001.htm