zoukankan      html  css  js  c++  java
  • 断点续传

    package com.zcp.xzsp;

    import java.io.File;

    import android.app.Activity;
    import android.os.Bundle;
    import android.os.Environment;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.TextView;

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

    public class MainActivity extends Activity {

    private Button b1;
    private String path="101.200.142.201:8080/tqyb/dancer.avi";
    private TextView testTextView;

    private String h;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    b1=(Button)findViewById(R.id.b1);
    testTextView= (TextView) findViewById(R.id.tv_info);
    b1.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
    if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
    File f = Environment.getExternalStorageDirectory();
    h=f.getPath();
    HttpUtils http = new HttpUtils();
    // 如果目标文件存在,接着未完成的部分继续下载。服务器不支持RANGE时将从新下载。
    // 如果从请求返回信息中获取到文件名,下载完成后自动重命名。
    http.download("http://101.200.142.201:8080/tqyb/dancer.avi",h+"/mj.mp4", true,true,new RequestCallBack<File>(){
    @Override
    public void onStart() {
    testTextView.setText("conn...");
    }
    @Override
    public void onLoading(long total, long current, boolean isUploading) {
    testTextView.setText(current + "/" + total);
    }
    @Override
    public void onSuccess(ResponseInfo<File> responseInfo) {
    testTextView.setText("downloaded:" + responseInfo.result.getPath());
    }
    @Override
    public void onFailure(HttpException error, String msg) {
    testTextView.setText(msg);
    }
    });
    }
    }
    });
    }


    }

    //xml布局

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <Button
    android:id="@+id/b1"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:text="开始下载"
    />
    <TextView
    android:id="@+id/tv_info"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:layout_below="@+id/b1"
    android:text="111"
    />
    </RelativeLayout>

  • 相关阅读:
    centos安装杂记inittabhostnamessh
    centos6安装aircrack,reaver1.4
    20175236 201820192 《Java程序设计》第五周学习总结
    20175236 201820192 《Java程序设计》第三周学习总结
    20175236 JAVA MyCP(课下作业)
    20175236 201820192 《Java程序设计》第六周学习总结
    小学生之Java中的异常
    小学生之面向对象的三个特征继承、封装、多态
    小学生之类与对象
    小学生之手(01)之 "for循环"
  • 原文地址:https://www.cnblogs.com/hnpy/p/5455211.html
Copyright © 2011-2022 走看看