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>

  • 相关阅读:
    ABAPNote001
    ABAPNote002
    共享WinCE6.0 下的一个软件升级程序
    EF参数化查询
    VS2010 调用RFC 时注意(.net4.0) 使用nco
    RDLC报表问题
    参数化查询与拼接SQL代码执行测试
    ABAPNOTE 获取释放的定单
    Wince6.0 + xpsp3+VS2005的一些问题
    BackgroundWorker使用备忘
  • 原文地址:https://www.cnblogs.com/hnpy/p/5455211.html
Copyright © 2011-2022 走看看