diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser
index 2264837..8cf026c 100644
Binary files a/.idea/caches/build_file_checksums.ser and b/.idea/caches/build_file_checksums.ser differ
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
index 2eb81ec..49f7b87 100644
--- a/.idea/codeStyles/Project.xml
+++ b/.idea/codeStyles/Project.xml
@@ -24,31 +24,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/.idea/markdown-navigator/profiles_settings.xml b/.idea/markdown-navigator/profiles_settings.xml
index 57927c5..db06266 100644
--- a/.idea/markdown-navigator/profiles_settings.xml
+++ b/.idea/markdown-navigator/profiles_settings.xml
@@ -1,3 +1,3 @@
-
+
\ No newline at end of file
diff --git a/README.md b/README.md
index 3681bf3..93501bc 100644
--- a/README.md
+++ b/README.md
@@ -39,7 +39,7 @@ AppUpdater for Android 是一个专注于App更新,一键傻瓜式集成App版
com.king.app
app-updater
- 1.0.3
+ 1.0.4
pom
@@ -47,27 +47,27 @@ AppUpdater for Android 是一个专注于App更新,一键傻瓜式集成App版
com.king.app
app-dialog
- 1.0.3
+ 1.0.4
pom
```
### Gradle:
```gradle
//app-updater
- implementation 'com.king.app:app-updater:1.0.3'
+ implementation 'com.king.app:app-updater:1.0.4'
//app-dialog
- implementation 'com.king.app:app-dialog:1.0.3'
+ implementation 'com.king.app:app-dialog:1.0.4'
```
### Lvy:
```lvy
//app-updater
-
+
//app-dialog
-
+
```
@@ -132,6 +132,9 @@ AppUpdater for Android 是一个专注于App更新,一键傻瓜式集成App版
## 版本记录
+#### v1.0.4:2019-6-4
+* 支持添加请求头
+
#### v1.0.3:2019-5-9
* 新增支持下载APK优先取本地缓存,避免多次下载相同版本的APK文件
* AppDialog支持隐藏Dialog的标题
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 a606b71..5be3487 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
@@ -53,7 +53,7 @@ public View createAppDialogView(@NonNull Context context,@NonNull AppDialogConfi
btnDialogCancel.setVisibility(config.isHideCancel() ? View.GONE : View.VISIBLE);
try{
- //不强制要求要有横线
+ //不强制要求要有中间的线
View line = view.findViewById(R.id.line);
line.setVisibility(config.isHideCancel() ? View.GONE : View.VISIBLE);
}catch (Exception e){
@@ -137,6 +137,7 @@ public String showDialogFragment(FragmentManager fragmentManager,DialogFragment
* @return
*/
public String showDialogFragment(FragmentManager fragmentManager,DialogFragment dialogFragment, String tag) {
+ dismissDialogFragment(fragmentManager);
dialogFragment.show(fragmentManager,tag);
mTag = tag;
return tag;
diff --git a/app-dialog/src/main/java/com/king/app/dialog/fragment/AppDialogFragment.java b/app-dialog/src/main/java/com/king/app/dialog/fragment/AppDialogFragment.java
index 38461a5..f3e3481 100644
--- a/app-dialog/src/main/java/com/king/app/dialog/fragment/AppDialogFragment.java
+++ b/app-dialog/src/main/java/com/king/app/dialog/fragment/AppDialogFragment.java
@@ -36,6 +36,7 @@ public void init(View rootView){
if(config!=null){
TextView tvDialogTitle = rootView.findViewById(config.getTitleId());
setText(tvDialogTitle,config.getTitle());
+ tvDialogTitle.setVisibility(config.isHideTitle() ? View.GONE : View.VISIBLE);
TextView tvDialogContent = rootView.findViewById(config.getContentId());
setText(tvDialogContent,config.getContent());
@@ -46,7 +47,7 @@ public void init(View rootView){
btnDialogCancel.setVisibility(config.isHideCancel() ? View.GONE : View.VISIBLE);
try{
- //不强制要求要有横线
+ //不强制要求要有中间的线
View line = rootView.findViewById(R.id.line);
line.setVisibility(config.isHideCancel() ? View.GONE : View.VISIBLE);
}catch (Exception e){
@@ -56,6 +57,7 @@ public void init(View rootView){
Button btnDialogOK = rootView.findViewById(config.getOkId());
setText(btnDialogOK,config.getOk());
btnDialogOK.setOnClickListener(config.getOnClickOk() != null ? config.getOnClickOk() : getOnClickDismiss());
+
}
}
}
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 6b64c29..ed8430e 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
@@ -8,7 +8,6 @@
import android.os.IBinder;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
-import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.util.Log;
@@ -18,6 +17,8 @@
import com.king.app.updater.service.DownloadService;
import com.king.app.updater.util.PermissionUtils;
+import java.util.Map;
+
/**
* @author Jenly Jenly
@@ -274,6 +275,27 @@ public Builder setVersionCode(Integer versionCode) {
return this;
}
+ /**
+ * 请求头添加参数
+ * @param key
+ * @param value
+ * @return
+ */
+ public Builder addHeader(String key, String value){
+ mConfig.addHeader(key,value);
+ return this;
+ }
+
+ /**
+ * 请求头添加参数
+ * @param headers
+ * @return
+ */
+ public Builder addHeader(Map headers){
+ mConfig.addHeader(headers);
+ 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 61d26f9..30f55bb 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
@@ -8,6 +8,9 @@
import com.king.app.updater.constant.Constants;
+import java.util.HashMap;
+import java.util.Map;
+
/**
* @author Jenly Jenly
@@ -79,6 +82,11 @@ public class UpdateConfig implements Parcelable {
*/
private Integer versionCode;
+ /**
+ * 请求头参数
+ */
+ private Map mRequestProperty;
+
public UpdateConfig() {
@@ -204,25 +212,24 @@ public void setVersionCode(Integer versionCode){
this.versionCode = versionCode;
}
- @Override
- public String toString() {
- return "UpdateConfig{" +
- "mUrl='" + mUrl + '\'' +
- ", mPath='" + mPath + '\'' +
- ", mFilename='" + mFilename + '\'' +
- ", isShowNotification=" + isShowNotification +
- ", isInstallApk=" + isInstallApk +
- ", mNotificationIcon=" + mNotificationIcon +
- ", mNotificationId=" + mNotificationId +
- ", mChannelId='" + mChannelId + '\'' +
- ", mChannelName='" + mChannelName + '\'' +
- ", mAuthority='" + mAuthority + '\'' +
- ", isReDownload=" + isReDownload +
- ", isShowPercentage=" + isShowPercentage +
- ", isVibrate=" + isVibrate +
- ", isSound=" + isSound +
- ", versionCode=" + versionCode +
- '}';
+ public Map getRequestProperty() {
+ return mRequestProperty;
+ }
+
+ public void addHeader(String key, String value){
+ initRequestProperty();
+ mRequestProperty.put(key,value);
+ }
+
+ public void addHeader(Map headers){
+ initRequestProperty();
+ mRequestProperty.putAll(headers);
+ }
+
+ private void initRequestProperty(){
+ if(mRequestProperty == null){
+ mRequestProperty = new HashMap<>();
+ }
}
@@ -248,6 +255,14 @@ public void writeToParcel(Parcel dest, int flags) {
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);
+ if(mRequestProperty!=null){
+ for (Map.Entry entry : this.mRequestProperty.entrySet()) {
+ dest.writeString(entry.getKey());
+ dest.writeString(entry.getValue());
+ }
+ }
+
}
protected UpdateConfig(Parcel in) {
@@ -266,6 +281,13 @@ protected UpdateConfig(Parcel in) {
this.isVibrate = in.readByte() != 0;
this.isSound = in.readByte() != 0;
this.versionCode = (Integer) in.readValue(Integer.class.getClassLoader());
+ int mRequestPropertySize = in.readInt();
+ this.mRequestProperty = new HashMap<>(mRequestPropertySize);
+ for (int i = 0; i < mRequestPropertySize; i++) {
+ String key = in.readString();
+ String value = in.readString();
+ this.mRequestProperty.put(key, value);
+ }
}
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 dcd9af8..95a3b2a 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
@@ -1,7 +1,11 @@
package com.king.app.updater.http;
import android.os.AsyncTask;
+import android.os.Build;
+import android.support.annotation.Nullable;
+import android.util.Log;
+import com.king.app.updater.constant.Constants;
import com.king.app.updater.util.SSLSocketFactoryUtils;
import java.io.File;
@@ -10,6 +14,7 @@
import java.net.ConnectException;
import java.net.HttpURLConnection;
import java.net.URL;
+import java.util.Map;
import javax.net.ssl.HttpsURLConnection;
@@ -20,7 +25,7 @@ public class HttpManager implements IHttpManager {
private static final int DEFAULT_TIME_OUT = 20000;
- private int mTimeout = DEFAULT_TIME_OUT;
+ private int mTimeout;
private static HttpManager INSTANCE;
@@ -43,8 +48,8 @@ public HttpManager(int timeout){
}
@Override
- public void download(String url, String path, String filename, DownloadCallback callback) {
- new DownloadTask(url,path,filename,callback).execute();
+ public void download(String url, String path, String filename, @Nullable Map requestProperty, DownloadCallback callback) {
+ new DownloadTask(url,path,filename,requestProperty,callback).execute();
}
@@ -58,15 +63,18 @@ private class DownloadTask extends AsyncTask {
private String filename;
+ private Map requestProperty;
+
private DownloadCallback callback;
private Exception exception;
- public DownloadTask(String url,String path,String filename,DownloadCallback callback){
+ public DownloadTask(String url, String path, String filename ,@Nullable Map requestProperty, DownloadCallback callback){
this.url = url;
this.path = path;
this.filename = filename;
this.callback = callback;
+ this.requestProperty = requestProperty;
}
@@ -78,17 +86,30 @@ protected File doInBackground(Void... voids) {
HttpsURLConnection.setDefaultHostnameVerifier(SSLSocketFactoryUtils.createTrustAllHostnameVerifier());
HttpURLConnection connect = (HttpURLConnection)new URL(url).openConnection();
connect.setRequestMethod("GET");
+ connect.setRequestProperty("Accept-Encoding", "identity");
+
connect.setReadTimeout(mTimeout);
connect.setConnectTimeout(mTimeout);
+
+ if(requestProperty!=null){
+ for(Map.Entry entry : requestProperty.entrySet()){
+ connect.setRequestProperty(entry.getKey(),entry.getValue());
+ }
+ }
+
connect.connect();
int responseCode = connect.getResponseCode();
-
+ Log.d(Constants.TAG,"Content-Type:" + connect.getContentType());
if(responseCode == HttpURLConnection.HTTP_OK){
InputStream is = connect.getInputStream();
int length = connect.getContentLength();
+ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+ length = (int)connect.getContentLengthLong();
+ }
+
int progress = 0;
byte[] buffer = new byte[4096];
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 b4bf124..a927a5f 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
@@ -1,7 +1,10 @@
package com.king.app.updater.http;
+import android.support.annotation.Nullable;
+
import java.io.File;
import java.io.Serializable;
+import java.util.Map;
/**
* @author Jenly Jenly
@@ -14,9 +17,10 @@ public interface IHttpManager {
* @param url
* @param path
* @param filename
+ * @param requestProperty
* @param callback
*/
- void download(String url,String path,String filename,DownloadCallback callback);
+ void download(String url, String path, String filename, @Nullable Map requestProperty, DownloadCallback callback);
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 c70dc1e..29106e8 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
@@ -7,8 +7,6 @@
import android.app.Service;
import android.content.Context;
import android.content.Intent;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageInfo;
import android.net.Uri;
import android.os.Binder;
import android.os.Build;
@@ -159,9 +157,9 @@ public void startDownload(UpdateConfig config,IHttpManager httpManager,UpdateCal
}
Log.d(Constants.TAG,"File:" + file);
if(httpManager != null){
- httpManager.download(url,path,filename,new AppDownloadCallback(config,callback));
+ httpManager.download(url,path,filename,config.getRequestProperty(),new AppDownloadCallback(config,callback));
}else{
- HttpManager.getInstance().download(url,path,filename,new AppDownloadCallback(config,callback));
+ HttpManager.getInstance().download(url,path,filename,config.getRequestProperty(),new AppDownloadCallback(config,callback));
}
}
@@ -516,6 +514,8 @@ private NotificationCompat.Builder buildNotification(String channelId,@DrawableR
if(progress!= Constants.NONE && size!=Constants.NONE){
builder.setProgress(size,progress,false);
+ }else{
+ builder.setProgress(0,0,true);
}
return builder;
@@ -545,7 +545,7 @@ public IBinder onBind(Intent intent) {
public class DownloadBinder extends Binder {
public void start(UpdateConfig config){
- start(config,null,null);
+ start(config,null);
}
public void start(UpdateConfig config,UpdateCallback callback){
diff --git a/app-updater/src/main/res/xml/app_updater_paths.xml b/app-updater/src/main/res/xml/app_updater_paths.xml
index d1d86b4..bc154c1 100644
--- a/app-updater/src/main/res/xml/app_updater_paths.xml
+++ b/app-updater/src/main/res/xml/app_updater_paths.xml
@@ -1,10 +1,11 @@
-
+
+
-
-
-
-
+
+
+
+
\ No newline at end of file
diff --git a/app/release/app-release.apk b/app/release/app-release.apk
index b7e4451..7c5e5ae 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 f72fe2b..bf5ffe2 100644
--- a/app/release/output.json
+++ b/app/release/output.json
@@ -1 +1 @@
-[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":4,"versionName":"1.0.3","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":5,"versionName":"1.0.4","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 501f784..e572638 100644
--- a/app/src/main/java/com/king/appupdater/MainActivity.java
+++ b/app/src/main/java/com/king/appupdater/MainActivity.java
@@ -28,8 +28,6 @@ public class MainActivity extends AppCompatActivity {
private final Object mLock = new Object();
- public final String TAG = this.getClass().getSimpleName();
-
private String mUrl = "https://raw.githubusercontent.com/jenly1314/AppUpdater/master/app/release/app-release.apk";
private ProgressBar progressBar;
@@ -75,6 +73,7 @@ private void clickBtn1(){
private void clickBtn2(){
UpdateConfig config = new UpdateConfig();
config.setUrl(mUrl);
+ config.addHeader("token","xxxxxx");
new AppUpdater(getContext(),config)
.setUpdateCallback(new UpdateCallback() {
diff --git a/versions.gradle b/versions.gradle
index 72b4e21..3008cea 100644
--- a/versions.gradle
+++ b/versions.gradle
@@ -1,7 +1,7 @@
//App
def app_version = [:]
-app_version.versionCode = 4
-app_version.versionName = "1.0.3"
+app_version.versionCode = 5
+app_version.versionName = "1.0.4"
ext.app_version = app_version
//build version