代码:http://download.csdn.net/detail/huangbin95487710/9258845
依赖包模式
完整运行还需要用到以下依赖包
- 下载管理器【DownLoadPop】
- 支持断点下载
- 支持后台下载
- 支持多线程下载
- 支持同步下载通知
- 可根据下载体DownlaodBase的以下属性,实现特殊定制
/** 状态开关*/ public boolean isCheckVersion = true;// 是否核对版本文件 public boolean isReStart = false;// 是否每次重新下载 public boolean isPopDialog = true;// 当存在文件时候是否弹出对话框提示用户 public boolean isShowNotice = true;// 是否有通知栏
- 代码实例
package cn.whonow.whonow.download; import General.DownLoad.Base.DownLoadBase; import General.System.MyLog; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import app.general.lib.DownLoadPop; import app.general.lib.DownLoadPopListener; import cn.whonow.whonow.R; /**必须实现DownLoadPopListener接口*/ public class DownLoadActivity extends Activity implements DownLoadPopListener { private DownLoadPop mDownLoadPop; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.test_download); mDownLoadPop = new DownLoadPop(this, this); Button mButtonTxt = (Button) findViewById(R.id.button1); mButtonTxt.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub DownLoadBase mBase = new DownLoadBase(); mBase.mKey = "uuid001"; mBase.mUrl = "http://soft.anruan.com/down.php?id=2333"; mBase.mSize = 940209; /**弹出loading框*/ mDownLoadPop.show(mBase); /**无下载进度条模式*/ //mDownLoadPop.run(mBase); } }); } @Override public void onDestroy() { // TODO Auto-generated method stub super.onDestroy(); if (mDownLoadPop != null) { mDownLoadPop.onDestroy(); } } @Override public void onDownloadSucess(DownLoadBase mBase) { // 下载成功! MyLog.show(this, "下载成功!" + mBase.mKey); } @Override public void onDownloadCancel(DownLoadBase mBase) { // 下载取消! MyLog.show(this, "下载取消!" + mBase.mKey); } }
- 效果图