diff --git a/.gitignore b/.gitignore
index 5edb4ee..09b993d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,9 +1,7 @@
*.iml
.gradle
/local.properties
-/.idea/libraries
-/.idea/modules.xml
-/.idea/workspace.xml
+/.idea
.DS_Store
/build
/captures
diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser
deleted file mode 100644
index 40675be..0000000
Binary files a/.idea/caches/build_file_checksums.ser and /dev/null differ
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
deleted file mode 100644
index 49f7b87..0000000
--- a/.idea/codeStyles/Project.xml
+++ /dev/null
@@ -1,52 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
deleted file mode 100644
index a1757ae..0000000
--- a/.idea/compiler.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/dbnavigator.xml b/.idea/dbnavigator.xml
deleted file mode 100644
index 8095114..0000000
--- a/.idea/dbnavigator.xml
+++ /dev/null
@@ -1,456 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
deleted file mode 100644
index 97626ba..0000000
--- a/.idea/encodings.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
deleted file mode 100644
index d28b75a..0000000
--- a/.idea/gradle.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/markdown-navigator.xml b/.idea/markdown-navigator.xml
deleted file mode 100644
index 7758d01..0000000
--- a/.idea/markdown-navigator.xml
+++ /dev/null
@@ -1,83 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/markdown-navigator/profiles_settings.xml b/.idea/markdown-navigator/profiles_settings.xml
deleted file mode 100644
index db06266..0000000
--- a/.idea/markdown-navigator/profiles_settings.xml
+++ /dev/null
@@ -1,3 +0,0 @@
-
-
-
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
deleted file mode 100644
index 51fa3e5..0000000
--- a/.idea/misc.xml
+++ /dev/null
@@ -1,44 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml
deleted file mode 100644
index 7f68460..0000000
--- a/.idea/runConfigurations.xml
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
deleted file mode 100644
index 35eb1dd..0000000
--- a/.idea/vcs.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/README.md b/README.md
index 0ecd93d..b8f7272 100644
--- a/README.md
+++ b/README.md
@@ -5,9 +5,10 @@
[![Download](https://img.shields.io/badge/download-App-blue.svg)](https://raw.githubusercontent.com/jenly1314/AppUpdater/master/app/release/app-release.apk)
[![Jitpack](https://jitpack.io/v/jenly1314/AppUpdater.svg)](https://jitpack.io/#jenly1314/AppUpdater)
[![CI](https://travis-ci.org/jenly1314/AppUpdater.svg?branch=master)](https://travis-ci.org/jenly1314/AppUpdater)
+[![CircleCI](https://circleci.com/gh/jenly1314/AppUpdater.svg?style=svg)](https://circleci.com/gh/jenly1314/AppUpdater)
[![API](https://img.shields.io/badge/API-15%2B-blue.svg?style=flat)](https://android-arsenal.com/api?level=15)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/mit-license.php)
-[![Blog](https://img.shields.io/badge/blog-Jenly-9933CC.svg)](http://blog.csdn.net/jenly121)
+[![Blog](https://img.shields.io/badge/blog-Jenly-9933CC.svg)](https://jenly1314.github.io/)
[![QQGroup](https://img.shields.io/badge/QQGroup-20867961-blue.svg)](http://shang.qq.com/wpa/qunwpa?idkey=8fcc6a2f88552ea44b1411582c94fd124f7bb3ec227e2a400dbbfaad3dc2f5ad)
AppUpdater for Android 是一个专注于App更新,一键傻瓜式集成App版本升级的开源库。(无需担心通知栏适配;无需担心重复点击下载;无需担心App安装等问题;这些AppUpdater都已帮您处理好。)
@@ -27,7 +28,6 @@ AppUpdater for Android 是一个专注于App更新,一键傻瓜式集成App版
- [x] 支持Android O
-
## Gif 展示
![Image](GIF.gif)
@@ -39,15 +39,15 @@ AppUpdater for Android 是一个专注于App更新,一键傻瓜式集成App版
com.king.app
app-updater
- 1.0.4
+ 1.0.5
pom
-
+
//app-dialog
com.king.app
app-dialog
- 1.0.4
+ 1.0.5
pom
```
@@ -56,25 +56,25 @@ AppUpdater for Android 是一个专注于App更新,一键傻瓜式集成App版
//----------AndroidX 版本
//app-updater
- implementation 'com.king.app:app-updater:1.0.4-androidx'
+ implementation 'com.king.app:app-updater:1.0.5-androidx'
//app-dialog
- implementation 'com.king.app:app-dialog:1.0.4-androidx'
-
+ implementation 'com.king.app:app-dialog:1.0.5-androidx'
+
//----------Android 版本
//app-updater
- implementation 'com.king.app:app-updater:1.0.4'
+ implementation 'com.king.app:app-updater:1.0.5'
//app-dialog
- implementation 'com.king.app:app-dialog:1.0.4'
+ implementation 'com.king.app:app-dialog:1.0.5'
```
### Lvy:
```lvy
//app-updater
-
+
-
+
//app-dialog
-
+
```
@@ -135,11 +135,14 @@ AppUpdater for Android 是一个专注于App更新,一键傻瓜式集成App版
```
-更多使用示例请查看[App](app)。
+更多使用详情,请查看[app](app)中的源码使用示例或直接查看[API帮助文档](https://jenly1314.github.io/projects/AppUpdater/doc/)
## 版本记录
-#### v1.0.4:2019-6-4 [支持AndroidX版本](https://github.com/jenly1314/AppUpdater/tree/androidx)
+#### v1.0.5:2019-9-4
+* 支持取消下载
+
+#### v1.0.4:2019-6-4 [支持AndroidX版本](https://github.com/jenly1314/AppUpdater/tree/androidx)
* 支持添加请求头
#### v1.0.3:2019-5-9
@@ -173,6 +176,8 @@ AppUpdater for Android 是一个专注于App更新,一键傻瓜式集成App版
CSDN: jenly121
+ 博客园: jenly
+
Github: jenly1314
加入QQ群: 20867961
diff --git a/app-dialog/src/main/java/com/king/app/dialog/AppDialog.java b/app-dialog/src/main/java/com/king/app/dialog/AppDialog.java
index 29efe2c..dfb1fba 100644
--- a/app-dialog/src/main/java/com/king/app/dialog/AppDialog.java
+++ b/app-dialog/src/main/java/com/king/app/dialog/AppDialog.java
@@ -87,6 +87,7 @@ public enum AppDialog {
public void dismissDialogFragment(FragmentManager fragmentManager){
dismissDialogFragment(fragmentManager,mTag);
+ mTag = null;
}
public void dismissDialogFragment(FragmentManager fragmentManager,String tag){
diff --git a/app-updater/src/main/AndroidManifest.xml b/app-updater/src/main/AndroidManifest.xml
index 1a466ab..16bef19 100644
--- a/app-updater/src/main/AndroidManifest.xml
+++ b/app-updater/src/main/AndroidManifest.xml
@@ -11,10 +11,10 @@
-
+
diff --git a/app-updater/src/main/java/com/king/app/updater/AppUpdater.java b/app-updater/src/main/java/com/king/app/updater/AppUpdater.java
index 4019f7c..672f332 100644
--- a/app-updater/src/main/java/com/king/app/updater/AppUpdater.java
+++ b/app-updater/src/main/java/com/king/app/updater/AppUpdater.java
@@ -112,6 +112,21 @@ public class AppUpdater {
}
}
+ /**
+ * 取消下载
+ */
+ public void stop(){
+ stopDownloadService();
+ }
+
+ /**
+ * 停止下载服务
+ */
+ private void stopDownloadService(){
+ Intent intent = new Intent(mContext, DownloadService.class);
+ intent.putExtra(Constants.KEY_STOP_DOWNLOAD_SERVICE,true);
+ mContext.startService(intent);
+ }
/**
* AppUpdater构建器
@@ -297,6 +312,16 @@ public class AppUpdater {
return this;
}
+ /**
+ * 设置是否自动删除取消下载的文件
+ * @param isDeleteCancelFile 是否删除取消下载的文件(默认为true)
+ * @return
+ */
+ public Builder setDeleteCancelFile(boolean isDeleteCancelFile){
+ mConfig.setDeleteCancelFile(isDeleteCancelFile);
+ return this;
+ }
+
public AppUpdater build(@NonNull Context context){
AppUpdater appUpdater = new AppUpdater(context,mConfig);
return appUpdater;
diff --git a/app-updater/src/main/java/com/king/app/updater/UpdateConfig.java b/app-updater/src/main/java/com/king/app/updater/UpdateConfig.java
index 74c9661..6df82e0 100644
--- a/app-updater/src/main/java/com/king/app/updater/UpdateConfig.java
+++ b/app-updater/src/main/java/com/king/app/updater/UpdateConfig.java
@@ -88,6 +88,11 @@ public class UpdateConfig implements Parcelable {
*/
private Map mRequestProperty;
+ /**
+ * 是否删除取消下载的文件
+ */
+ private boolean isDeleteCancelFile = true;
+
public UpdateConfig() {
@@ -234,6 +239,15 @@ public class UpdateConfig implements Parcelable {
}
+ public boolean isDeleteCancelFile() {
+ return isDeleteCancelFile;
+ }
+
+ public void setDeleteCancelFile(boolean deleteCancelFile) {
+ isDeleteCancelFile = deleteCancelFile;
+ }
+
+
@Override
public int describeContents() {
return 0;
@@ -256,14 +270,14 @@ public class UpdateConfig implements Parcelable {
dest.writeByte(this.isVibrate ? (byte) 1 : (byte) 0);
dest.writeByte(this.isSound ? (byte) 1 : (byte) 0);
dest.writeValue(this.versionCode);
- dest.writeInt(mRequestProperty!=null ? this.mRequestProperty.size():0);
+ dest.writeInt(mRequestProperty!=null ? this.mRequestProperty.size() : 0);
if(mRequestProperty!=null){
for (Map.Entry entry : this.mRequestProperty.entrySet()) {
dest.writeString(entry.getKey());
dest.writeString(entry.getValue());
}
}
-
+ dest.writeByte(this.isDeleteCancelFile ? (byte) 1 : (byte) 0);
}
protected UpdateConfig(Parcel in) {
@@ -289,6 +303,7 @@ public class UpdateConfig implements Parcelable {
String value = in.readString();
this.mRequestProperty.put(key, value);
}
+ this.isDeleteCancelFile = in.readByte() != 0;
}
public static final Creator CREATOR = new Creator() {
diff --git a/app-updater/src/main/java/com/king/app/updater/http/HttpManager.java b/app-updater/src/main/java/com/king/app/updater/http/HttpManager.java
index e6323c0..7cb17a6 100644
--- a/app-updater/src/main/java/com/king/app/updater/http/HttpManager.java
+++ b/app-updater/src/main/java/com/king/app/updater/http/HttpManager.java
@@ -28,6 +28,8 @@ public class HttpManager implements IHttpManager {
private int mTimeout;
+ private boolean isCancel;
+
private static HttpManager INSTANCE;
public static HttpManager getInstance(){
@@ -50,9 +52,14 @@ public class HttpManager implements IHttpManager {
@Override
public void download(String url, String path, String filename, @Nullable Map requestProperty, DownloadCallback callback) {
+ isCancel = false;
new DownloadTask(url,path,filename,requestProperty,callback).execute();
}
+ @Override
+ public void cancel() {
+ isCancel = true;
+ }
/**
* 异步下载任务
@@ -119,6 +126,10 @@ public class HttpManager implements IHttpManager {
File file = new File(path,filename);
FileOutputStream fos = new FileOutputStream(file);
while ((len = is.read(buffer)) != -1){
+ if(isCancel){
+ cancel(true);
+ break;
+ }
fos.write(buffer,0,len);
progress += len;
//更新进度
@@ -169,7 +180,10 @@ public class HttpManager implements IHttpManager {
protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
if(callback!=null){
- callback.onProgress(values[0],values[1]);
+ if(!isCancelled()){
+ callback.onProgress(values[0],values[1]);
+ }
+
}
}
diff --git a/app-updater/src/main/java/com/king/app/updater/http/IHttpManager.java b/app-updater/src/main/java/com/king/app/updater/http/IHttpManager.java
index 9b2cb7a..74f2523 100644
--- a/app-updater/src/main/java/com/king/app/updater/http/IHttpManager.java
+++ b/app-updater/src/main/java/com/king/app/updater/http/IHttpManager.java
@@ -23,6 +23,10 @@ public interface IHttpManager {
*/
void download(String url, String path, String filename, @Nullable Map requestProperty, DownloadCallback callback);
+ /**
+ * 取消下载
+ */
+ void cancel();
interface DownloadCallback extends Serializable{
/**
diff --git a/app-updater/src/main/java/com/king/app/updater/service/DownloadService.java b/app-updater/src/main/java/com/king/app/updater/service/DownloadService.java
index c61483f..9568fc8 100644
--- a/app-updater/src/main/java/com/king/app/updater/service/DownloadService.java
+++ b/app-updater/src/main/java/com/king/app/updater/service/DownloadService.java
@@ -55,6 +55,10 @@ public class DownloadService extends Service {
*/
private int mCount = 0;
+ private IHttpManager mHttpManager;
+
+ private File mFile;
+
private Context getContext(){
return this;
}
@@ -63,20 +67,19 @@ public class DownloadService extends Service {
public int onStartCommand(Intent intent, int flags, int startId) {
if(intent != null){
- if(!isDownloading){
- boolean isStop = intent.getBooleanExtra(Constants.KEY_STOP_DOWNLOAD_SERVICE,false);
- if(isStop){
- stopService();
- }else{
- //是否实通过通知栏触发重复下载
- boolean isReDownload = intent.getBooleanExtra(Constants.KEY_RE_DOWNLOAD,false);
- if(isReDownload){
- mCount++;
- }
- //获取配置信息
- UpdateConfig config = intent.getParcelableExtra(Constants.KEY_UPDATE_CONFIG);
- startDownload(config,null,null);
+
+ boolean isStop = intent.getBooleanExtra(Constants.KEY_STOP_DOWNLOAD_SERVICE,false);
+ if(isStop){
+ stopDownload();
+ } else if(!isDownloading){
+ //是否实通过通知栏触发重复下载
+ boolean isReDownload = intent.getBooleanExtra(Constants.KEY_RE_DOWNLOAD,false);
+ if(isReDownload){
+ mCount++;
}
+ //获取配置信息
+ UpdateConfig config = intent.getParcelableExtra(Constants.KEY_UPDATE_CONFIG);
+ startDownload(config,null,null);
}else{
Log.w(Constants.TAG,"Please do not repeat the download.");
}
@@ -128,23 +131,23 @@ public class DownloadService extends Service {
filename = AppUtils.INSTANCE.getAppFullName(getContext(),url,getResources().getString(R.string.app_name));
}
- File file = new File(path,filename);
- if(file.exists()){//文件是否存在
+ mFile = new File(path,filename);
+ if(mFile.exists()){//文件是否存在
Integer versionCode = config.getVersionCode();
if(versionCode!=null){
try{
- if(AppUtils.INSTANCE.apkExists(getContext(),versionCode,file)){
+ if(AppUtils.INSTANCE.apkExists(getContext(),versionCode,mFile)){
//本地已经存在要下载的APK
- Log.d(Constants.TAG,"CacheFile:" + file);
+ Log.d(Constants.TAG,"CacheFile:" + mFile);
if(config.isInstallApk()){
String authority = config.getAuthority();
if(TextUtils.isEmpty(authority)){//如果为空则默认
authority = getContext().getPackageName() + ".fileProvider";
}
- AppUtils.INSTANCE.installApk(getContext(),file,authority);
+ AppUtils.INSTANCE.installApk(getContext(),mFile,authority);
}
if(callback!=null){
- callback.onFinish(file);
+ callback.onFinish(mFile);
}
stopService();
return;
@@ -154,17 +157,28 @@ public class DownloadService extends Service {
}
}
//删除旧文件
- file.delete();
+ mFile.delete();
}
- Log.d(Constants.TAG,"File:" + file);
+ Log.d(Constants.TAG,"File:" + mFile);
+
if(httpManager != null){
- httpManager.download(url,path,filename,config.getRequestProperty(),new AppDownloadCallback(config,callback));
+ mHttpManager = httpManager;
}else{
- HttpManager.getInstance().download(url,path,filename,config.getRequestProperty(),new AppDownloadCallback(config,callback));
+ mHttpManager = HttpManager.getInstance();
}
+ mHttpManager.download(url,path,filename,config.getRequestProperty(),new AppDownloadCallback(config,callback));
}
+ /**
+ * 停止下载
+ */
+ public void stopDownload(){
+ if(mHttpManager!=null){
+ mHttpManager.cancel();
+ }
+ }
+
/**
* 获取缓存路径
* @param context
@@ -327,6 +341,9 @@ public class DownloadService extends Service {
if(callback!=null){
callback.onCancel();
}
+ if(mFile!=null){
+ mFile.delete();
+ }
stopService();
}
}
@@ -334,6 +351,7 @@ public class DownloadService extends Service {
@Override
public void onDestroy() {
isDownloading = false;
+ mHttpManager = null;
super.onDestroy();
}
diff --git a/app-updater/src/main/java/com/king/app/updater/util/AppUtils.java b/app-updater/src/main/java/com/king/app/updater/util/AppUtils.java
index d5c92a0..fba4e5e 100644
--- a/app-updater/src/main/java/com/king/app/updater/util/AppUtils.java
+++ b/app-updater/src/main/java/com/king/app/updater/util/AppUtils.java
@@ -104,7 +104,7 @@ public enum AppUtils {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addCategory(Intent.CATEGORY_DEFAULT);
- Uri uriData = null;
+ Uri uriData;
String type = "application/vnd.android.package-archive";
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N){
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
diff --git a/app/release/app-release.apk b/app/release/app-release.apk
index c039881..67425f2 100644
Binary files a/app/release/app-release.apk and b/app/release/app-release.apk differ
diff --git a/app/release/output.json b/app/release/output.json
index f36d4d7..38ad7a2 100644
--- a/app/release/output.json
+++ b/app/release/output.json
@@ -1 +1 @@
-[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":6,"versionName":"1.0.4-androidx","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
\ No newline at end of file
+[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":8,"versionName":"1.0.5-androidx","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
\ No newline at end of file
diff --git a/app/src/main/java/com/king/appupdater/MainActivity.java b/app/src/main/java/com/king/appupdater/MainActivity.java
index 7b7f74d..0b0a112 100644
--- a/app/src/main/java/com/king/appupdater/MainActivity.java
+++ b/app/src/main/java/com/king/appupdater/MainActivity.java
@@ -35,6 +35,8 @@ public class MainActivity extends AppCompatActivity {
private Toast toast;
+ private AppUpdater mAppUpdater;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -65,7 +67,8 @@ public class MainActivity extends AppCompatActivity {
* 简单一键后台升级
*/
private void clickBtn1(){
- new AppUpdater(getContext(),mUrl).start();
+ mAppUpdater = new AppUpdater(getContext(),mUrl);
+ mAppUpdater.start();
}
/**
@@ -75,7 +78,7 @@ public class MainActivity extends AppCompatActivity {
UpdateConfig config = new UpdateConfig();
config.setUrl(mUrl);
config.addHeader("token","xxxxxx");
- new AppUpdater(getContext(),config)
+ mAppUpdater = new AppUpdater(getContext(),config)
.setUpdateCallback(new UpdateCallback() {
@Override
@@ -113,8 +116,8 @@ public class MainActivity extends AppCompatActivity {
public void onCancel() {
progressBar.setVisibility(View.INVISIBLE);
}
- })
- .start();
+ });
+ mAppUpdater.start();
}
/**
@@ -127,7 +130,7 @@ public class MainActivity extends AppCompatActivity {
.setPositiveButton("升级", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
- new AppUpdater.Builder()
+ mAppUpdater = new AppUpdater.Builder()
.serUrl(mUrl)
.build(getContext())
.setUpdateCallback(new AppUpdateCallback() {
@@ -140,8 +143,8 @@ public class MainActivity extends AppCompatActivity {
public void onFinish(File file) {
showToast("下载完成");
}
- })
- .start();
+ });
+ mAppUpdater.start();
}
}).show();
}
@@ -157,7 +160,8 @@ public class MainActivity extends AppCompatActivity {
.setOnClickOk(new View.OnClickListener() {
@Override
public void onClick(View v) {
- new AppUpdater(getContext(),mUrl).start();
+ mAppUpdater = new AppUpdater(getContext(),mUrl);
+ mAppUpdater.start();
AppDialog.INSTANCE.dismissDialog();
}
});
@@ -177,10 +181,10 @@ public class MainActivity extends AppCompatActivity {
.setOnClickOk(new View.OnClickListener() {
@Override
public void onClick(View v) {
- new AppUpdater.Builder()
+ mAppUpdater = new AppUpdater.Builder()
.serUrl(mUrl)
- .build(getContext())
- .start();
+ .build(getContext());
+ mAppUpdater.start();
AppDialog.INSTANCE.dismissDialog();
}
});
@@ -209,14 +213,14 @@ public class MainActivity extends AppCompatActivity {
btnOK.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- new AppUpdater.Builder()
+ mAppUpdater = new AppUpdater.Builder()
.serUrl(mUrl)
.setPath(Environment.getExternalStorageDirectory() + "/.AppUpdater")
.setVersionCode(BuildConfig.VERSION_CODE)//设置versionCode之后,新版本相同的apk只下载一次,优先取本地缓存。
.setFilename("AppUpdater1.apk")
.setVibrate(true)
- .build(getContext())
- .start();
+ .build(getContext());
+ mAppUpdater.start();
AppDialog.INSTANCE.dismissDialog();
}
});
@@ -235,12 +239,12 @@ public class MainActivity extends AppCompatActivity {
.setOnClickOk(new View.OnClickListener() {
@Override
public void onClick(View v) {
- new AppUpdater.Builder()
+ mAppUpdater = new AppUpdater.Builder()
.serUrl(mUrl)
.setVibrate(true)
.setSound(true)
- .build(getContext())
- .start();
+ .build(getContext());
+ mAppUpdater.start();
AppDialog.INSTANCE.dismissDialogFragment(getSupportFragmentManager());
}
});
@@ -248,6 +252,13 @@ public class MainActivity extends AppCompatActivity {
}
+ private void clickCancel(){
+ if(mAppUpdater != null){
+ mAppUpdater.stop();
+ }
+
+ }
+
public void OnClick(View v){
switch (v.getId()){
case R.id.btn1:
@@ -271,6 +282,9 @@ public class MainActivity extends AppCompatActivity {
case R.id.btn7:
clickBtn7();
break;
+ case R.id.btnCancel:
+ clickCancel();
+ break;
}
}
}
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index afc5180..ada176c 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -104,4 +104,17 @@
app:layout_constraintRight_toRightOf="parent"
style="@style/OnClick"/>
+
+
\ No newline at end of file
diff --git a/versions.gradle b/versions.gradle
index 3316de5..cffd7db 100644
--- a/versions.gradle
+++ b/versions.gradle
@@ -1,7 +1,7 @@
//App
def app_version = [:]
-app_version.versionCode = 6 //androidx 6
-app_version.versionName = "1.0.4-androidx"
+app_version.versionCode = 8 //androidx 8
+app_version.versionName = "1.0.5-androidx"
ext.app_version = app_version
//build version