AppUpdate
AppUpdate copied to clipboard
如何接入只使用下载安装功能
如题,我这边已经有接口能获取到下载的URL地址,如何只使用您的下载,下载进度条和状态栏下载进度条的功能了?看了 您写的java.md文档,虽然可以自定义接口和实现HttpManager,但没太看明白怎么使用,感觉不太好接入,求解答,非常感谢。
UpdateAppBean updateAppBean = new UpdateAppBean();
//设置 apk 的下载地址
updateAppBean.setApkFileUrl("https://raw.githubusercontent.com/WVector/AppUpdateDemo/master/apk/app-debug.apk");
String path = "";
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED) || !Environment.isExternalStorageRemovable()) {
try {
path = getExternalCacheDir().getAbsolutePath();
} catch (Exception e) {
e.printStackTrace();
}
if (TextUtils.isEmpty(path)) {
path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath();
}
} else {
path = getCacheDir().getAbsolutePath();
}
//设置apk 的保存路径
updateAppBean.setTargetPath(path);
//实现网络接口,只实现下载就可以
updateAppBean.setHttpManager(new UpdateAppHttpUtil());
UpdateAppManager.download(this, updateAppBean, new DownloadService.DownloadCallback() {
@Override
public void onStart() {
HProgressDialogUtils.showHorizontalProgressDialog(JavaActivity.this, "下载进度", false);
Log.d(TAG, "onStart() called");
}
@Override
public void onProgress(float progress, long totalSize) {
HProgressDialogUtils.setProgress(Math.round(progress * 100));
Log.d(TAG, "onProgress() called with: progress = [" + progress + "], totalSize = [" + totalSize + "]");
}
@Override
public void setMax(long totalSize) {
Log.d(TAG, "setMax() called with: totalSize = [" + totalSize + "]");
}
@Override
public boolean onFinish(File file) {
HProgressDialogUtils.cancel();
Log.d(TAG, "onFinish() called with: file = [" + file.getAbsolutePath() + "]");
return true;
}
@Override
public void onError(String msg) {
HProgressDialogUtils.cancel();
Log.e(TAG, "onError() called with: msg = [" + msg + "]");
}
@Override
public boolean onInstallAppAndAppOnForeground(File file) {
Log.d(TAG, "onInstallAppAndAppOnForeground() called with: file = [" + file + "]");
return false;
}
});