|
|
@ -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; |
|
|
|
} |
|
|
|
} |
|
|
|