优化细节

pull/27/head
Jenly 4 years ago
parent 727cd08b98
commit 3ee62c3b32
  1. 14
      app-updater/src/main/java/com/king/app/updater/AppUpdater.java
  2. 92
      app-updater/src/main/java/com/king/app/updater/UpdateConfig.java
  3. BIN
      app/release/app-release.apk
  4. 18
      app/release/output-metadata.json
  5. 1
      app/release/output.json

@ -168,6 +168,7 @@ public class AppUpdater {
* 设置保存的路径建议使用默认不做设置 * 设置保存的路径建议使用默认不做设置
* @param path 下载保存的文件路径 * @param path 下载保存的文件路径
* @return * @return
* @deprecated 因为适配Android Q的分区存储所以此方法已弃用不建议再使用
*/ */
@Deprecated @Deprecated
public Builder setPath(String path){ public Builder setPath(String path){
@ -197,11 +198,11 @@ public class AppUpdater {
/** /**
* 设置通知ID * 设置通知ID
* @param notifyId 通知ID * @param notificationId 通知ID
* @return * @return
*/ */
public Builder setNotificationId(int notifyId) { public Builder setNotificationId(int notificationId) {
mConfig.setNotificationId(notifyId); mConfig.setNotificationId(notificationId);
return this; return this;
} }
@ -353,11 +354,10 @@ public class AppUpdater {
/** /**
* 设置是否自动删除取消下载的文件 * 设置是否自动删除取消下载的文件
* @param isDeleteCancelFile 是否删除取消下载的文件默认为true * @param deleteCancelFile 是否删除取消下载的文件默认为true
* @return
*/ */
public Builder setDeleteCancelFile(boolean isDeleteCancelFile){ public Builder setDeleteCancelFile(boolean deleteCancelFile){
mConfig.setDeleteCancelFile(isDeleteCancelFile); mConfig.setDeleteCancelFile(deleteCancelFile);
return this; return this;
} }

@ -111,6 +111,10 @@ public class UpdateConfig implements Parcelable {
return mUrl; return mUrl;
} }
/**
* 设置APK下载地址
* @param url 下载地址
*/
public void setUrl(String url) { public void setUrl(String url) {
this.mUrl = url; this.mUrl = url;
} }
@ -119,6 +123,13 @@ public class UpdateConfig implements Parcelable {
return mPath; return mPath;
} }
/**
* 设置保存的路径建议使用默认不做设置
* @param path 下载保存的文件路径
* @return
* @deprecated 因为适配Android Q的分区存储所以此方法已弃用不建议再使用
*/
@Deprecated
public void setPath(String path) { public void setPath(String path) {
this.mPath = path; this.mPath = path;
} }
@ -127,6 +138,10 @@ public class UpdateConfig implements Parcelable {
return mFilename; return mFilename;
} }
/**
* 设置保存的文件名
* @param filename 下载的保存的apk文件名 默认优先取url文件名
*/
public void setFilename(String filename) { public void setFilename(String filename) {
this.mFilename = filename; this.mFilename = filename;
} }
@ -135,6 +150,10 @@ public class UpdateConfig implements Parcelable {
return isShowNotification; return isShowNotification;
} }
/**
* 设置是否显示通知栏
* @param isShowNotification 是否显示通知栏 默认true
*/
public void setShowNotification(boolean isShowNotification) { public void setShowNotification(boolean isShowNotification) {
this.isShowNotification = isShowNotification; this.isShowNotification = isShowNotification;
} }
@ -143,6 +162,10 @@ public class UpdateConfig implements Parcelable {
return mChannelId; return mChannelId;
} }
/**
* 设置通知渠道ID
* @param channelId 通知渠道ID 默认兼容O
*/
public void setChannelId(String channelId) { public void setChannelId(String channelId) {
this.mChannelId = channelId; this.mChannelId = channelId;
} }
@ -151,10 +174,17 @@ public class UpdateConfig implements Parcelable {
return mChannelName; return mChannelName;
} }
/**
* 设置通知渠道名称
* @param channelName 通知渠道名称 默认兼容O
*/
public void setChannelName(String channelName) { public void setChannelName(String channelName) {
this.mChannelName = channelName; this.mChannelName = channelName;
} }
/**
* 设置通知ID
* @param notificationId 通知ID
*/
public void setNotificationId(int notificationId){ public void setNotificationId(int notificationId){
this.mNotificationId = notificationId; this.mNotificationId = notificationId;
} }
@ -163,6 +193,11 @@ public class UpdateConfig implements Parcelable {
return this.mNotificationId; return this.mNotificationId;
} }
/**
* 设置通知图标
* @param icon 通知栏图标 默认取App的icon
*/
public void setNotificationIcon(@DrawableRes int icon){ public void setNotificationIcon(@DrawableRes int icon){
this.mNotificationIcon = icon; this.mNotificationIcon = icon;
} }
@ -175,6 +210,10 @@ public class UpdateConfig implements Parcelable {
return isInstallApk; return isInstallApk;
} }
/**
* 设置下载完成后知否自动触发安装APK
* @param isInstallApk 下载完成后是否自动调用安装APK默认true
*/
public void setInstallApk(boolean isInstallApk) { public void setInstallApk(boolean isInstallApk) {
this.isInstallApk = isInstallApk; this.isInstallApk = isInstallApk;
} }
@ -183,6 +222,10 @@ public class UpdateConfig implements Parcelable {
return mAuthority; return mAuthority;
} }
/**
* 设置FileProvider的authority
* @param authority FileProvider的authority默认兼容N默认值{@link Context#getPackageName() + ".fileProvider"}
*/
public void setAuthority(String authority) { public void setAuthority(String authority) {
this.mAuthority = authority; this.mAuthority = authority;
} }
@ -191,6 +234,10 @@ public class UpdateConfig implements Parcelable {
return isShowPercentage; return isShowPercentage;
} }
/**
* 设置下载时通知栏是否显示下载百分比
* @param showPercentage 下载时通知栏是否显示百分比
*/
public void setShowPercentage(boolean showPercentage) { public void setShowPercentage(boolean showPercentage) {
isShowPercentage = showPercentage; isShowPercentage = showPercentage;
} }
@ -199,6 +246,10 @@ public class UpdateConfig implements Parcelable {
return isReDownload; return isReDownload;
} }
/**
* 设置下载失败时是否支持点击通知栏重新下载与之相关联的方法{@link #setReDownloads(int)}
* @param reDownload 下载失败时是否支持点击通知栏重新下载默认true
*/
public void setReDownload(boolean reDownload) { public void setReDownload(boolean reDownload) {
isReDownload = reDownload; isReDownload = reDownload;
} }
@ -207,6 +258,10 @@ public class UpdateConfig implements Parcelable {
return reDownloads; return reDownloads;
} }
/**
* 设置下载失败时最多重新下载次数与之相关联的方法{@link #setReDownload(boolean)}
* @param reDownloads 下载失败时是否支持点击通知栏重新下载默认最多重新下载3次
*/
public void setReDownloads(int reDownloads) { public void setReDownloads(int reDownloads) {
this.reDownloads = reDownloads; this.reDownloads = reDownloads;
} }
@ -215,6 +270,10 @@ public class UpdateConfig implements Parcelable {
return isVibrate; return isVibrate;
} }
/**
* 设置通知是否震动提示
* @param vibrate 是否震动提示为true时使用通知默认震动Android O(8.0)以上设置只有初次创建channel时有效后续修改属性无效想要重新有效需修改channelId或卸载App重装
*/
public void setVibrate(boolean vibrate) { public void setVibrate(boolean vibrate) {
isVibrate = vibrate; isVibrate = vibrate;
} }
@ -223,6 +282,10 @@ public class UpdateConfig implements Parcelable {
return isSound; return isSound;
} }
/**
* 设置通知是否铃声提示
* @param sound 是否铃声提示为true时使用通知默认铃声Android O(8.0)以上设置只有初次创建channel时有效后续修改属性无效想要重新有效需修改channelId或卸载App重装
*/
public void setSound(boolean sound) { public void setSound(boolean sound) {
isSound = sound; isSound = sound;
} }
@ -231,6 +294,13 @@ public class UpdateConfig implements Parcelable {
return versionCode; return versionCode;
} }
/**
* 设置要下载APK的versionCode用于优先取缓存时通过versionCode校验APK文件是否一致
* 缓存校验目前支持两种方式一种是通过versionCode校验{@link #setVersionCode(Integer)}一种是文件MD5校验{@link #setApkMD5(String)}推荐使用MD5校验方式
* 如果两种方式都设置了则只校验MD5
* @param versionCode 为null表示不处理默认不存在则下载存在则重新下载不为null时表示会优先校验本地是否存在已下载版本号为versionCode的APK
* 如果存在则不会重新下载(AppUpdater会自动校验packageName一致性)直接取本地APK反之重新下载
*/
public void setVersionCode(Integer versionCode){ public void setVersionCode(Integer versionCode){
this.versionCode = versionCode; this.versionCode = versionCode;
} }
@ -239,7 +309,12 @@ public class UpdateConfig implements Parcelable {
return mRequestProperty; return mRequestProperty;
} }
/**
* 设置APK文件的MD5用于优先取缓存时通过MD5校验文件APK是否一致
* 缓存校验目前支持两种方式一种是通过versionCode校验{@link #setVersionCode(Integer)}一种是文件MD5校验{@link #setApkMD5(String)}推荐使用MD5校验方式
* 如果两种方式都设置了则只校验MD5
* @param md5 为null表示不处理如果设置了MD5则缓存APK的MD5相同时只下载一次优先取本地缓存
*/
public void setApkMD5(String md5){ public void setApkMD5(String md5){
this.apkMD5 = md5; this.apkMD5 = md5;
} }
@ -248,11 +323,20 @@ public class UpdateConfig implements Parcelable {
return apkMD5; return apkMD5;
} }
/**
* 请求头添加参数
* @param key
* @param value
*/
public void addHeader(String key, String value){ public void addHeader(String key, String value){
initRequestProperty(); initRequestProperty();
mRequestProperty.put(key,value); mRequestProperty.put(key,value);
} }
/**
* 请求头添加参数
* @param headers
*/
public void addHeader(Map<String,String> headers){ public void addHeader(Map<String,String> headers){
initRequestProperty(); initRequestProperty();
mRequestProperty.putAll(headers); mRequestProperty.putAll(headers);
@ -268,6 +352,10 @@ public class UpdateConfig implements Parcelable {
return isDeleteCancelFile; return isDeleteCancelFile;
} }
/**
* 设置是否自动删除取消下载的文件
* @param deleteCancelFile 是否删除取消下载的文件默认为true
*/
public void setDeleteCancelFile(boolean deleteCancelFile) { public void setDeleteCancelFile(boolean deleteCancelFile) {
isDeleteCancelFile = deleteCancelFile; isDeleteCancelFile = deleteCancelFile;
} }

Binary file not shown.

@ -0,0 +1,18 @@
{
"version": 2,
"artifactType": {
"type": "APK",
"kind": "Directory"
},
"applicationId": "com.king.appupdater",
"variantName": "processReleaseResources",
"elements": [
{
"type": "SINGLE",
"filters": [],
"versionCode": 18,
"versionName": "1.0.10-androidx",
"outputFile": "app-release.apk"
}
]
}

@ -1 +0,0 @@
[{"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":{}}]
Loading…
Cancel
Save