调用xUtils-master的api实现下载

发布时间:2020-04-23 12:15:33 作者:秋寒526
来源:网络 阅读:593

一丶使用xUtils-master的API实现下载文件

点击下载:public void click(View view){

        HttpUtils http = new HttpUtils();

        String path = etpath.getText().toString();//拿到下载的的服务地址

//"/mnt/sdcard/txdx.mp3":下载到机子的目录;true:是否支持断点下载

       http.download(path,"/mnt/sdcard/txdx.mp3",true,new RequestCallBack<File>() {
            
            @Override
            public void onSuccess(ResponseInfo<File> arg0) {
                Toast.makeText(MainActivity.this, "下载成功", 0).show() ;
            }
            
            @Override
            public void onFailure(HttpException arg0, String arg1) {
            }
            
            @Override
            public void onLoading(long total, long current, boolean isUploading) {
                super.onLoading(total, current, isUploading);
                pb.setMax((int)total) ;//设置进度条最大的进度
                
                pb.setProgress((int)current) ;//设置当前的进度
            }
        }) ;

}

注:1.进度条布局

<ProgressBar
        android:id="@+id/pb"
       
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

2.xUtils-master下载api附件中

推荐阅读:
  1. ElasticSearch的API python调用
  2. 使用django怎么实现API接口的互相调用

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

下载文件 断点 public

上一篇:Centos是如何安装MySQL数据库的

下一篇:全栈增长工程师指南

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》