-
Notifications
You must be signed in to change notification settings - Fork 29
DownloadListener
huxq17 edited this page Jul 6, 2019
·
7 revisions
Filter the download information to be received, all received by default.
downloading.
download success.
download failed.
Get DownloadInfo.
Get download status.
Disable this observer and Pump will remove this observer later.
Enable this Observer.
Listen all download task:
DownloadListener downloadObserver = 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.
downloadObserver.enable();
}
@Override
protected void onStop() {
super.onStop();
//Disable this observer and Pump will remove this observer later.
downloadObserver.disable();
}
Listen special task:
Pump.newRequest(url5, pipixiaFile.getAbsolutePath())
//listen url5 download progress.
.listener(new DownloadListener(url5) {
@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();
@Override
protected void onStop() {
super.onStop();
//unSubscribe url5 download listener.
Pump.unSubscribe(url5);
}