diff --git a/README.md b/README.md
index 045c151..1398d7e 100644
--- a/README.md
+++ b/README.md
@@ -3,7 +3,7 @@
![Image](app/src/main/ic_launcher-web.png)
[![Download](https://img.shields.io/badge/download-App-blue.svg)](https://raw.githubusercontent.com/jenly1314/AppUpdater/master/app/release/app-release.apk)
-[![JCenter](https://img.shields.io/badge/JCenter-1.0.9-46C018.svg)](https://bintray.com/beta/#/jenly/maven/app-updater)
+[![JCenter](https://img.shields.io/badge/JCenter-1.0.10-46C018.svg)](https://bintray.com/beta/#/jenly/maven/app-updater)
[![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)
@@ -42,7 +42,7 @@ AppUpdater for Android 是一个专注于App更新,一键傻瓜式集成App版
com.king.app
app-updater
- 1.0.9
+ 1.0.10
pom
@@ -50,7 +50,7 @@ AppUpdater for Android 是一个专注于App更新,一键傻瓜式集成App版
com.king.app
app-dialog
- 1.0.9
+ 1.0.10
pom
```
@@ -59,25 +59,25 @@ AppUpdater for Android 是一个专注于App更新,一键傻瓜式集成App版
//----------AndroidX 版本
//app-updater
- implementation 'com.king.app:app-updater:1.0.9-androidx'
+ implementation 'com.king.app:app-updater:1.0.10-androidx'
//app-dialog
- implementation 'com.king.app:app-dialog:1.0.9-androidx'
+ implementation 'com.king.app:app-dialog:1.0.10-androidx'
//----------Android Support 版本
//app-updater
- implementation 'com.king.app:app-updater:1.0.9'
+ implementation 'com.king.app:app-updater:1.0.10'
//app-dialog
- implementation 'com.king.app:app-dialog:1.0.9'
+ implementation 'com.king.app:app-dialog:1.0.10'
```
### Lvy:
```lvy
//app-updater
-
+
//app-dialog
-
+
```
@@ -100,7 +100,7 @@ AppUpdater for Android 是一个专注于App更新,一键傻瓜式集成App版
```
```Java
//简单弹框升级
- AppDialogConfig config = new AppDialogConfig();
+ AppDialogConfig config = new AppDialogConfig(context);
config.setTitle("简单弹框升级")
.setOk("升级")
.setContent("1、新增某某功能、\n2、修改某某问题、\n3、优化某某BUG、")
@@ -108,7 +108,7 @@ AppUpdater for Android 是一个专注于App更新,一键傻瓜式集成App版
@Override
public void onClick(View v) {
new AppUpdater.Builder()
- .serUrl(mUrl)
+ .setUrl(mUrl)
.build(getContext())
.start();
AppDialog.INSTANCE.dismissDialog();
@@ -118,7 +118,7 @@ AppUpdater for Android 是一个专注于App更新,一键傻瓜式集成App版
```
```Java
//简单DialogFragment升级
- AppDialogConfig config = new AppDialogConfig();
+ AppDialogConfig config = new AppDialogConfig(context);
config.setTitle("简单DialogFragment升级")
.setOk("升级")
.setContent("1、新增某某功能、\n2、修改某某问题、\n3、优化某某BUG、")
@@ -126,7 +126,7 @@ AppUpdater for Android 是一个专注于App更新,一键傻瓜式集成App版
@Override
public void onClick(View v) {
new AppUpdater.Builder()
- .serUrl(mUrl)
+ .setUrl(mUrl)
.setFilename("AppUpdater.apk")
.build(getContext())
.setHttpManager(OkHttpManager.getInstance())//不设置HttpManager时,默认使用HttpsURLConnection下载,如果使用OkHttpClient实现下载,需依赖okhttp库
@@ -148,6 +148,10 @@ AppUpdater for Android 是一个专注于App更新,一键傻瓜式集成App版
## 版本记录
+#### v1.0.10:2021-3-4
+* AppDialogConfig添加构造参数,简化自定义扩展用法
+* 优化细节
+
#### v1.0.9:2020-12-11
* 优化默认Dialog样式的显示细节
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 de52483..16626cc 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
@@ -74,6 +74,7 @@ public class HttpManager implements IHttpManager {
* 异步下载任务
*/
private class DownloadTask extends AsyncTask {
+
private String url;
private String path;
@@ -103,7 +104,7 @@ public class HttpManager implements IHttpManager {
connect.setReadTimeout(mTimeout);
connect.setConnectTimeout(mTimeout);
- if(requestProperty!=null){
+ if(requestProperty != null){
for(Map.Entry entry : requestProperty.entrySet()){
connect.setRequestProperty(entry.getKey(),entry.getValue());
}
@@ -151,6 +152,10 @@ public class HttpManager implements IHttpManager {
connect.disconnect();
+ if(progress <= 0 && length <= 0){
+ throw new IllegalStateException(String.format("contentLength = %d",length));
+ }
+
return file;
}
case HttpURLConnection.HTTP_MULT_CHOICE:
@@ -188,7 +193,7 @@ public class HttpManager implements IHttpManager {
@Override
protected void onPreExecute() {
super.onPreExecute();
- if(callback!=null){
+ if(callback != null){
callback.onStart(url);
}
}
@@ -196,8 +201,8 @@ public class HttpManager implements IHttpManager {
@Override
protected void onPostExecute(File file) {
super.onPostExecute(file);
- if(callback!=null){
- if(file!=null){
+ if(callback != null){
+ if(file != null){
callback.onFinish(file);
}else{
callback.onError(exception);
@@ -209,7 +214,7 @@ public class HttpManager implements IHttpManager {
@Override
protected void onProgressUpdate(Long... values) {
super.onProgressUpdate(values);
- if(callback!=null){
+ if(callback != null){
if(!isCancelled()){
callback.onProgress(values[0],values[1]);
}
@@ -220,7 +225,7 @@ public class HttpManager implements IHttpManager {
@Override
protected void onCancelled() {
super.onCancelled();
- if(callback!=null){
+ if(callback != null){
callback.onCancel();
}
}
diff --git a/app-updater/src/main/java/com/king/app/updater/http/OkHttpManager.java b/app-updater/src/main/java/com/king/app/updater/http/OkHttpManager.java
index 7180c57..a1b00a8 100644
--- a/app-updater/src/main/java/com/king/app/updater/http/OkHttpManager.java
+++ b/app-updater/src/main/java/com/king/app/updater/http/OkHttpManager.java
@@ -76,7 +76,7 @@ public class OkHttpManager implements IHttpManager {
@Override
- public void download(String url, final String path, final String filename, @Nullable Map requestProperty, final DownloadCallback callback) {
+ public void download(String url,final String path,final String filename, @Nullable Map requestProperty,final DownloadCallback callback) {
isCancel = false;
new DownloadTask(okHttpClient,url,path,filename,requestProperty,callback).execute();
}
@@ -90,7 +90,7 @@ public class OkHttpManager implements IHttpManager {
/**
* 异步下载任务
*/
- private class DownloadTask extends AsyncTask {
+ private class DownloadTask extends AsyncTask {
private String url;
private String path;
@@ -158,7 +158,7 @@ public class OkHttpManager implements IHttpManager {
fos.write(buffer,0,len);
progress += len;
//更新进度
- if(length>0){
+ if(length > 0){
publishProgress(progress,length);
}
}
@@ -169,6 +169,10 @@ public class OkHttpManager implements IHttpManager {
response.close();
+ if(progress <= 0 && length <= 0){
+ throw new IllegalStateException(String.format("contentLength = %d",length));
+ }
+
return file;
}else {//连接失败
@@ -186,7 +190,7 @@ public class OkHttpManager implements IHttpManager {
@Override
protected void onPreExecute() {
super.onPreExecute();
- if(callback!=null){
+ if(callback != null){
callback.onStart(url);
}
}
@@ -194,8 +198,8 @@ public class OkHttpManager implements IHttpManager {
@Override
protected void onPostExecute(File file) {
super.onPostExecute(file);
- if(callback!=null){
- if(file!=null){
+ if(callback != null){
+ if(file != null){
callback.onFinish(file);
}else{
callback.onError(exception);
@@ -207,7 +211,7 @@ public class OkHttpManager implements IHttpManager {
@Override
protected void onProgressUpdate(Long... values) {
super.onProgressUpdate(values);
- if(callback!=null){
+ if(callback != null){
if(!isCancelled()){
callback.onProgress(values[0],values[1]);
}
@@ -218,10 +222,10 @@ public class OkHttpManager implements IHttpManager {
@Override
protected void onCancelled() {
super.onCancelled();
- if(callback!=null){
+ if(callback != null){
callback.onCancel();
}
}
}
-}
+}
\ No newline at end of file
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 fdd3a50..d843977 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
@@ -1,9 +1,5 @@
package com.king.app.updater.service;
-import android.app.Notification;
-import android.app.NotificationChannel;
-import android.app.NotificationManager;
-import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
@@ -20,13 +16,11 @@ import com.king.app.updater.constant.Constants;
import com.king.app.updater.http.HttpManager;
import com.king.app.updater.http.IHttpManager;
import com.king.app.updater.util.AppUtils;
+import com.king.app.updater.util.NotificationUtils;
import java.io.File;
-import androidx.annotation.DrawableRes;
import androidx.annotation.Nullable;
-import androidx.annotation.RequiresApi;
-import androidx.core.app.NotificationCompat;
import androidx.core.content.ContextCompat;
@@ -251,7 +245,7 @@ public class DownloadService extends Service {
this.channelId = TextUtils.isEmpty(config.getChannelId()) ? Constants.DEFAULT_NOTIFICATION_CHANNEL_ID : config.getChannelId();
this.channelName = TextUtils.isEmpty(config.getChannelName()) ? Constants.DEFAULT_NOTIFICATION_CHANNEL_NAME : config.getChannelName();
}
- if(config.getNotificationIcon() <=0 ){
+ if(config.getNotificationIcon() <= 0){
this.notificationIcon = AppUtils.getAppIcon(getContext());
}else{
this.notificationIcon = config.getNotificationIcon();
@@ -276,7 +270,7 @@ public class DownloadService extends Service {
isDownloading = true;
mLastProgress = 0;
if(isShowNotification){
- showStartNotification(notifyId,channelId,channelName,notificationIcon,getString(R.string.app_updater_start_notification_title),getString(R.string.app_updater_start_notification_content),config.isVibrate(),config.isSound());
+ NotificationUtils.showStartNotification(getContext(),notifyId,channelId,channelName,notificationIcon,getString(R.string.app_updater_start_notification_title),getString(R.string.app_updater_start_notification_content),config.isVibrate(),config.isSound());
}
if(callback!=null){
@@ -303,7 +297,7 @@ public class DownloadService extends Service {
content += percentage;
}
- showProgressNotification(notifyId, channelId, notificationIcon, getString(R.string.app_updater_progress_notification_title), content, currProgress, 100);
+ NotificationUtils.showProgressNotification(getContext(),notifyId, channelId, notificationIcon, getString(R.string.app_updater_progress_notification_title), content, currProgress, 100);
}
}
@@ -318,7 +312,7 @@ public class DownloadService extends Service {
public void onFinish(File file) {
Log.d(Constants.TAG,"onFinish:" + file);
isDownloading = false;
- showFinishNotification(notifyId,channelId,notificationIcon,getString(R.string.app_updater_finish_notification_title),getString(R.string.app_updater_finish_notification_content),file,authority);
+ NotificationUtils.showFinishNotification(getContext(),notifyId,channelId,notificationIcon,getString(R.string.app_updater_finish_notification_title),getString(R.string.app_updater_finish_notification_content),file,authority);
if(isInstallApk){
AppUtils.installApk(getContext(),file,authority);
}
@@ -335,7 +329,7 @@ public class DownloadService extends Service {
//支持下载失败时重新下载,当重新下载次数不超过限制时才被允许
boolean isReDownload = this.isReDownload && mCount < reDownloads;
String content = isReDownload ? getString(R.string.app_updater_error_notification_content_re_download) : getString(R.string.app_updater_error_notification_content);
- showErrorNotification(notifyId,channelId,notificationIcon,getString(R.string.app_updater_error_notification_title),content,isReDownload,config);
+ NotificationUtils.showErrorNotification(getContext(),notifyId,channelId,notificationIcon,getString(R.string.app_updater_error_notification_title),content,isReDownload,config);
if(callback!=null){
callback.onError(e);
@@ -350,7 +344,7 @@ public class DownloadService extends Service {
public void onCancel() {
Log.d(Constants.TAG,"onCancel");
isDownloading = false;
- cancelNotification(notifyId);
+ NotificationUtils.cancelNotification(getContext(),notifyId);
if(callback!=null){
callback.onCancel();
}
@@ -368,191 +362,6 @@ public class DownloadService extends Service {
super.onDestroy();
}
- //---------------------------------------- Notification
-
- /**
- * 显示开始下载是的通知
- * @param notifyId
- * @param channelId
- * @param channelName
- * @param icon
- * @param title
- * @param content
- */
- private void showStartNotification(int notifyId,String channelId, String channelName,@DrawableRes int icon,CharSequence title,CharSequence content,boolean isVibrate,boolean isSound){
- if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
- createNotificationChannel(channelId,channelName,isVibrate,isSound);
- }
- NotificationCompat.Builder builder = buildNotification(channelId,icon,title,content);
- builder.setPriority(NotificationManager.IMPORTANCE_HIGH);
- if(isVibrate && isSound){
- builder.setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND);
- }else if(isVibrate){
- builder.setDefaults(Notification.DEFAULT_VIBRATE);
- }else if(isSound){
- builder.setDefaults(Notification.DEFAULT_SOUND);
- }
-
- Notification notification = builder.build();
- notification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONLY_ALERT_ONCE;
- notifyNotification(notifyId,notification);
- }
-
- /**
- * 显示下载中的通知(更新进度)
- * @param notifyId
- * @param channelId
- * @param icon
- * @param title
- * @param content
- * @param progress
- * @param size
- */
- private void showProgressNotification(int notifyId,String channelId,@DrawableRes int icon,CharSequence title,CharSequence content,int progress,int size){
- NotificationCompat.Builder builder = buildNotification(channelId,icon,title,content,progress,size);
-
- Notification notification = builder.build();
- notification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONLY_ALERT_ONCE;
- notifyNotification(notifyId,notification);
- }
-
- /**
- * 显示下载完成时的通知(点击安装)
- * @param notifyId
- * @param channelId
- * @param icon
- * @param title
- * @param content
- * @param file
- */
- private void showFinishNotification(int notifyId,String channelId,@DrawableRes int icon,CharSequence title,CharSequence content,File file,String authority){
- cancelNotification(notifyId);
- NotificationCompat.Builder builder = buildNotification(channelId,icon,title,content);
- builder.setAutoCancel(true);
- Intent intent = AppUtils.getInstallIntent(getContext(),file,authority);
- PendingIntent clickIntent = PendingIntent.getActivity(getContext(), notifyId,intent, PendingIntent.FLAG_UPDATE_CURRENT);
- builder.setContentIntent(clickIntent);
- Notification notification = builder.build();
- notification.flags = Notification.FLAG_AUTO_CANCEL;
- notifyNotification(notifyId,notification);
- }
-
- private void showErrorNotification(int notifyId,String channelId,@DrawableRes int icon,CharSequence title,CharSequence content,boolean isReDownload,UpdateConfig config){
- NotificationCompat.Builder builder = buildNotification(channelId,icon,title,content);
- builder.setAutoCancel(true);
- if(isReDownload){//重新下载
- Intent intent = new Intent(getContext(),DownloadService.class);
- intent.putExtra(Constants.KEY_RE_DOWNLOAD,true);
- intent.putExtra(Constants.KEY_UPDATE_CONFIG,config);
- PendingIntent clickIntent = PendingIntent.getService(getContext(), notifyId,intent, PendingIntent.FLAG_UPDATE_CURRENT);
- builder.setContentIntent(clickIntent);
- }else{
- PendingIntent clickIntent = PendingIntent.getService(getContext(), notifyId,new Intent(), PendingIntent.FLAG_UPDATE_CURRENT);
- builder.setContentIntent(clickIntent);
- }
-
- Notification notification = builder.build();
- notification.flags = Notification.FLAG_AUTO_CANCEL;
- notifyNotification(notifyId,notification);
- }
-
-
- /**
- * 显示通知信息(非第一次)
- * @param notifyId
- * @param channelId
- * @param icon
- * @param title
- * @param content
- */
- private void showNotification(int notifyId,String channelId,@DrawableRes int icon,CharSequence title,CharSequence content,boolean isAutoCancel){
- NotificationCompat.Builder builder = buildNotification(channelId,icon,title,content);
- builder.setAutoCancel(isAutoCancel);
- Notification notification = builder.build();
- notification.flags = Notification.FLAG_AUTO_CANCEL;
- notifyNotification(notifyId,notification);
- }
-
- /**
- * 取消通知
- * @param notifyId
- */
- private void cancelNotification(int notifyId){
- getNotificationManager().cancel(notifyId);
- }
-
-
- /**
- * 获取通知管理器
- * @return
- */
- private NotificationManager getNotificationManager(){
- return (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
- }
-
- /**
- * 创建一个通知渠道(兼容0以上版本)
- * @param channelId
- * @param channelName
- */
- @RequiresApi(api = Build.VERSION_CODES.O)
- private void createNotificationChannel(String channelId, String channelName,boolean isVibrate,boolean isSound){
- NotificationChannel channel = new NotificationChannel(channelId,channelName, NotificationManager.IMPORTANCE_HIGH);
- channel.enableVibration(isVibrate);
- if(!isSound){
- channel.setSound(null,null);
- }
- getNotificationManager().createNotificationChannel(channel);
-
- }
-
- /**
- * 构建一个通知构建器
- * @param channelId
- * @param icon
- * @param title
- * @param content
- * @return
- */
- private NotificationCompat.Builder buildNotification(String channelId, @DrawableRes int icon,CharSequence title,CharSequence content){
- return buildNotification(channelId,icon,title,content,Constants.NONE,Constants.NONE);
- }
-
- /**
- * 构建一个通知构建器
- * @param channelId
- * @param icon
- * @param title
- * @param content
- * @param progress
- * @param size
- * @return
- */
- private NotificationCompat.Builder buildNotification(String channelId,@DrawableRes int icon,CharSequence title,CharSequence content,int progress,int size){
- NotificationCompat.Builder builder = new NotificationCompat.Builder(getContext(),channelId);
- builder.setSmallIcon(icon);
-
- builder.setContentTitle(title);
- builder.setContentText(content);
- builder.setOngoing(true);
-
- if(progress!= Constants.NONE && size!=Constants.NONE){
- builder.setProgress(size,progress,false);
- }
-
- return builder;
- }
-
- /**
- * 更新通知栏
- * @param id
- * @param notification
- */
- private void notifyNotification(int id, Notification notification){
- getNotificationManager().notify(id,notification);
- }
-
-
//---------------------------------------- Binder
@Nullable
diff --git a/app-updater/src/main/java/com/king/app/updater/util/NotificationUtils.java b/app-updater/src/main/java/com/king/app/updater/util/NotificationUtils.java
new file mode 100644
index 0000000..9b8308d
--- /dev/null
+++ b/app-updater/src/main/java/com/king/app/updater/util/NotificationUtils.java
@@ -0,0 +1,223 @@
+package com.king.app.updater.util;
+
+import android.app.Notification;
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Build;
+
+import com.king.app.updater.UpdateConfig;
+import com.king.app.updater.constant.Constants;
+import com.king.app.updater.service.DownloadService;
+
+import java.io.File;
+
+import androidx.annotation.DrawableRes;
+import androidx.annotation.RequiresApi;
+import androidx.core.app.NotificationCompat;
+
+/**
+ * @author Jenly
+ */
+public class NotificationUtils {
+
+ private NotificationUtils(){
+ throw new AssertionError();
+ }
+
+ /**
+ * 显示开始下载是的通知
+ * @param notifyId
+ * @param channelId
+ * @param channelName
+ * @param icon
+ * @param title
+ * @param content
+ */
+ public static void showStartNotification(Context context, int notifyId,String channelId, String channelName,@DrawableRes int icon,CharSequence title,CharSequence content,boolean isVibrate,boolean isSound){
+ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
+ createNotificationChannel(context,channelId,channelName,isVibrate,isSound);
+ }
+ NotificationCompat.Builder builder = buildNotification(context,channelId,icon,title,content);
+ builder.setPriority(NotificationManager.IMPORTANCE_HIGH);
+ if(isVibrate && isSound){
+ builder.setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND);
+ }else if(isVibrate){
+ builder.setDefaults(Notification.DEFAULT_VIBRATE);
+ }else if(isSound){
+ builder.setDefaults(Notification.DEFAULT_SOUND);
+ }
+
+ Notification notification = builder.build();
+ notification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONLY_ALERT_ONCE;
+ notifyNotification(context,notifyId,notification);
+ }
+
+ /**
+ * 显示下载中的通知(更新进度)
+ * @param notifyId
+ * @param channelId
+ * @param icon
+ * @param title
+ * @param content
+ * @param progress
+ * @param size
+ */
+ public static void showProgressNotification(Context context, int notifyId,String channelId,@DrawableRes int icon,CharSequence title,CharSequence content,int progress,int size){
+ NotificationCompat.Builder builder = buildNotification(context,channelId,icon,title,content,progress,size);
+
+ Notification notification = builder.build();
+ notification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONLY_ALERT_ONCE;
+ notifyNotification(context,notifyId,notification);
+ }
+
+ /**
+ * 显示下载完成时的通知(点击安装)
+ * @param notifyId
+ * @param channelId
+ * @param icon
+ * @param title
+ * @param content
+ * @param file
+ */
+ public static void showFinishNotification(Context context, int notifyId, String channelId, @DrawableRes int icon, CharSequence title, CharSequence content, File file, String authority){
+ cancelNotification(context,notifyId);
+ NotificationCompat.Builder builder = buildNotification(context,channelId,icon,title,content);
+ builder.setAutoCancel(true);
+ Intent intent = AppUtils.getInstallIntent(context,file,authority);
+ PendingIntent clickIntent = PendingIntent.getActivity(context, notifyId,intent, PendingIntent.FLAG_UPDATE_CURRENT);
+ builder.setContentIntent(clickIntent);
+ Notification notification = builder.build();
+ notification.flags = Notification.FLAG_AUTO_CANCEL;
+ notifyNotification(context,notifyId,notification);
+ }
+
+ /**
+ * 现在下载失败通知
+ * @param context
+ * @param notifyId
+ * @param channelId
+ * @param icon
+ * @param title
+ * @param content
+ * @param isReDownload
+ * @param config
+ */
+ public static void showErrorNotification(Context context, int notifyId, String channelId, @DrawableRes int icon, CharSequence title, CharSequence content, boolean isReDownload, UpdateConfig config){
+ NotificationCompat.Builder builder = buildNotification(context,channelId,icon,title,content);
+ builder.setAutoCancel(true);
+ if(isReDownload){//重新下载
+ Intent intent = new Intent(context, DownloadService.class);
+ intent.putExtra(Constants.KEY_RE_DOWNLOAD,true);
+ intent.putExtra(Constants.KEY_UPDATE_CONFIG,config);
+ PendingIntent clickIntent = PendingIntent.getService(context, notifyId,intent, PendingIntent.FLAG_UPDATE_CURRENT);
+ builder.setContentIntent(clickIntent);
+ }else{
+ PendingIntent clickIntent = PendingIntent.getService(context, notifyId,new Intent(), PendingIntent.FLAG_UPDATE_CURRENT);
+ builder.setContentIntent(clickIntent);
+ }
+
+ Notification notification = builder.build();
+ notification.flags = Notification.FLAG_AUTO_CANCEL;
+ notifyNotification(context,notifyId,notification);
+ }
+
+
+ /**
+ * 显示通知信息(非第一次)
+ * @param notifyId
+ * @param channelId
+ * @param icon
+ * @param title
+ * @param content
+ */
+ public static void showNotification(Context context, int notifyId,String channelId,@DrawableRes int icon,CharSequence title,CharSequence content,boolean isAutoCancel){
+ NotificationCompat.Builder builder = buildNotification(context,channelId,icon,title,content);
+ builder.setAutoCancel(isAutoCancel);
+ Notification notification = builder.build();
+ notification.flags = Notification.FLAG_AUTO_CANCEL;
+ notifyNotification(context,notifyId,notification);
+ }
+
+ /**
+ * 取消通知
+ * @param notifyId
+ */
+ public static void cancelNotification(Context context, int notifyId){
+ getNotificationManager(context).cancel(notifyId);
+ }
+
+
+ /**
+ * 获取通知管理器
+ * @return
+ */
+ public static NotificationManager getNotificationManager(Context context){
+ return (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
+ }
+
+ /**
+ * 创建一个通知渠道(兼容0以上版本)
+ * @param channelId
+ * @param channelName
+ */
+ @RequiresApi(api = Build.VERSION_CODES.O)
+ public static void createNotificationChannel(Context context, String channelId, String channelName,boolean isVibrate,boolean isSound){
+ NotificationChannel channel = new NotificationChannel(channelId,channelName, NotificationManager.IMPORTANCE_HIGH);
+ channel.enableVibration(isVibrate);
+ if(!isSound){
+ channel.setSound(null,null);
+ }
+ getNotificationManager(context).createNotificationChannel(channel);
+
+ }
+
+ /**
+ * 构建一个通知构建器
+ * @param channelId
+ * @param icon
+ * @param title
+ * @param content
+ * @return
+ */
+ private static NotificationCompat.Builder buildNotification(Context context, String channelId, @DrawableRes int icon,CharSequence title,CharSequence content){
+ return buildNotification(context,channelId,icon,title,content,Constants.NONE,Constants.NONE);
+ }
+
+ /**
+ * 构建一个通知构建器
+ * @param channelId
+ * @param icon
+ * @param title
+ * @param content
+ * @param progress
+ * @param size
+ * @return
+ */
+ private static NotificationCompat.Builder buildNotification(Context context, String channelId, @DrawableRes int icon, CharSequence title, CharSequence content, int progress, int size){
+ NotificationCompat.Builder builder = new NotificationCompat.Builder(context,channelId);
+ builder.setSmallIcon(icon);
+
+ builder.setContentTitle(title);
+ builder.setContentText(content);
+ builder.setOngoing(true);
+
+ if(progress!= Constants.NONE && size!=Constants.NONE){
+ builder.setProgress(size,progress,false);
+ }
+
+ return builder;
+ }
+
+ /**
+ * 更新通知栏
+ * @param id
+ * @param notification
+ */
+ private static void notifyNotification(Context context, int id, Notification notification){
+ getNotificationManager(context).notify(id,notification);
+ }
+
+}
diff --git a/app-updater/src/main/res/values/strings.xml b/app-updater/src/main/res/values/strings.xml
index 36d23be..928517b 100644
--- a/app-updater/src/main/res/values/strings.xml
+++ b/app-updater/src/main/res/values/strings.xml
@@ -5,7 +5,7 @@
正在获取下载数据…
版本更新
- 下载更新中…
+ 正在下载…
下载完成
点击安装
diff --git a/app/release/app-release.apk b/app/release/app-release.apk
new file mode 100644
index 0000000..b58ca5b
Binary files /dev/null and b/app/release/app-release.apk differ
diff --git a/app/release/output.json b/app/release/output.json
new file mode 100644
index 0000000..7cc91da
--- /dev/null
+++ b/app/release/output.json
@@ -0,0 +1 @@
+[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":18,"versionName":"1.0.10-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/versions.gradle b/versions.gradle
index 02d5ae2..b93fb90 100644
--- a/versions.gradle
+++ b/versions.gradle
@@ -1,7 +1,7 @@
//App
def app_version = [:]
-app_version.versionCode = 16 //androidx 16
-app_version.versionName = "1.0.9-androidx"
+app_version.versionCode = 18 //androidx 18
+app_version.versionName = "1.0.10-androidx"
ext.app_version = app_version
//build version