-
Notifications
You must be signed in to change notification settings - Fork 29
DownloadListener
空的构造函数,适用于后台下载
Empty constructor,for download in the background.
DownloadListener可以感知activity的生命周期,并且在页面销毁的时候自动移除监听,很智能并且不会造成内存泄漏
DownloadListener can aware of activity's lifecycle, and will remove this listener when the activity is destroyed.
DownloadListener可以感知fragment的生命周期,并且在页面销毁的时候自动移除监听。
DownloadListener can aware of fragment's lifecycle, and will remove this listener when the fragment is destroyed.
禁用此监听,并且Pump会移除它。
Disable this downloadListener and Pump will remove this downloadListener later.
启用此监听,开始接收下载进度和结果。
Enable this downloadListener,start receiving download progress and results.
downloading.
download success.
download failed.
Get DownloadInfo.
Get download status.
Filter the download information to be received, all received by default.
Listen all download task:
DownloadListener downloadListener = new DownloadListener() {
@Override
public void onProgress(int progress) {
progressDialog.setProgress(progress);
}
@Override
public boolean filter(DownloadInfo downloadInfo) {
String url = downloadInfo.getUrl();
return url.equals(url5);
}
@Override
public void onSuccess() {
progressDialog.dismiss();
String apkPath = getDownloadInfo().getFilePath();
APK.with(MainActivity.this)
.from(apkPath)
// .forceInstall();
.install();
Toast.makeText(MainActivity.this, "Download Finished", Toast.LENGTH_SHORT).show();
}
@Override
public void onFailed() {
progressDialog.dismiss();
}
};
@Override
protected void onStart() {
super.onStart();
//Enable this Observer.
downloadListener.enable();
}
@Override
protected void onStop() {
super.onStop();
//Disable this listener and Pump will remove this observer later.
downloadListener.disable();
}
Listen special task:
Pump.newRequest(url5, pipixiaFile.getAbsolutePath())
//listen url5 download progress.
.listener(new DownloadListener(MainActivity.this) {
@Override
public void onProgress(int progress) {
progressDialog.setProgress(progress);
}
@Override
public void onSuccess() {
Toast.makeText(MainActivity.this, "Download Finished", Toast.LENGTH_SHORT).show();
}
@Override
public void onFailed() {
Toast.makeText(MainActivity.this, "Download failed", Toast.LENGTH_SHORT).show();
}
})
.submit();