From 9eb484492d3e91c9db53c858220681f43c365114 Mon Sep 17 00:00:00 2001 From: maning Date: Wed, 30 Jun 2021 17:43:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8A=A8=E6=80=81=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E4=B8=8B=E8=BD=BD=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/caches/build_file_checksums.ser | Bin 589 -> 589 bytes app/build.gradle | 4 + .../com/maning/mnupdateapk/MainActivity.java | 87 ++++++++- .../bean/PgyerAppCheckResultBean.java | 174 ++++++++++++++++++ .../mnupdateapk/{ => cons}/Constants.java | 4 +- .../{ => utils}/PermissionUtils.java | 2 +- app/src/main/res/layout/activity_main.xml | 9 + 7 files changed, 270 insertions(+), 10 deletions(-) create mode 100644 app/src/main/java/com/maning/mnupdateapk/bean/PgyerAppCheckResultBean.java rename app/src/main/java/com/maning/mnupdateapk/{ => cons}/Constants.java (59%) rename app/src/main/java/com/maning/mnupdateapk/{ => utils}/PermissionUtils.java (97%) diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index 3e2ef95c1796a1eddfc7bee710adad000e75dc29..5b1fac00133bab91f56e0047d318e1b227d02e13 100644 GIT binary patch delta 32 qcmV+*0N?-31kD7HnFC6#zp3B0TIiRDKxGJx%god!0jSH@E~~LUk(KT diff --git a/app/build.gradle b/app/build.gradle index daf06e3..8682901 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,6 +47,10 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.appcompat:appcompat:1.0.0' + implementation 'com.android.volley:volley:1.1.1' + implementation 'com.google.code.gson:gson:2.8.5' + implementation 'com.github.maning0303:MNProgressHUD:V2.0.0X' + implementation 'com.squareup.okhttp3:okhttp:3.11.0' implementation project(':library_update') diff --git a/app/src/main/java/com/maning/mnupdateapk/MainActivity.java b/app/src/main/java/com/maning/mnupdateapk/MainActivity.java index bb456c4..8229ae0 100755 --- a/app/src/main/java/com/maning/mnupdateapk/MainActivity.java +++ b/app/src/main/java/com/maning/mnupdateapk/MainActivity.java @@ -4,19 +4,36 @@ import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; -import androidx.annotation.NonNull; -import androidx.appcompat.app.AlertDialog; -import androidx.appcompat.app.AppCompatActivity; +import android.text.TextUtils; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.app.AppCompatActivity; + +import com.android.volley.AuthFailureError; +import com.android.volley.Request; +import com.android.volley.RequestQueue; +import com.android.volley.Response; +import com.android.volley.VolleyError; +import com.android.volley.toolbox.StringRequest; +import com.android.volley.toolbox.Volley; +import com.google.gson.Gson; +import com.maning.mndialoglibrary.MProgressDialog; +import com.maning.mndialoglibrary.MToast; +import com.maning.mnupdateapk.bean.PgyerAppCheckResultBean; +import com.maning.mnupdateapk.cons.Constants; +import com.maning.mnupdateapk.utils.PermissionUtils; import com.maning.updatelibrary.InstallUtils; import java.io.File; import java.io.FileInputStream; +import java.util.HashMap; +import java.util.Map; public class MainActivity extends AppCompatActivity implements View.OnClickListener { @@ -33,6 +50,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe private Button btnOther; private InstallUtils.DownloadCallBack downloadCallBack; private String apkDownloadPath; + private Button mGetDownloadUrl; @Override @@ -41,25 +59,68 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_main); context = this; - initViews(); + initView(); initCallBack(); - } - private void initViews() { + private void initView() { tv_progress = (TextView) findViewById(R.id.tv_progress); tv_info = (TextView) findViewById(R.id.tv_info); btnDownload = (Button) findViewById(R.id.btnDownload); btnCancle = (Button) findViewById(R.id.btnCancle); btnDownloadBrowser = (Button) findViewById(R.id.btnDownloadBrowser); btnOther = (Button) findViewById(R.id.btnOther); - + mGetDownloadUrl = (Button) findViewById(R.id.getDownloadUrl); btnDownload.setOnClickListener(this); btnCancle.setOnClickListener(this); btnDownloadBrowser.setOnClickListener(this); btnOther.setOnClickListener(this); + mGetDownloadUrl.setOnClickListener(this); + } + + private void getAppUpdateInfo() { + MProgressDialog.showProgress(this); + RequestQueue queue = Volley.newRequestQueue(this); + String url = "https://www.pgyer.com/apiv2/app/check"; + // Request a string response from the provided URL. + StringRequest stringRequest = new StringRequest(Request.Method.POST, url, + new Response.Listener() { + @Override + public void onResponse(String response) { + MProgressDialog.dismissProgress(); + if(!TextUtils.isEmpty(response)){ + PgyerAppCheckResultBean result = new Gson().fromJson(response, PgyerAppCheckResultBean.class); + if (result != null && result.getCode() == 0 && result.getData() != null) { + PgyerAppCheckResultBean.Data data = result.getData(); + String downloadURL = data.getDownloadURL(); + Log.e("======","downloadURL:"+downloadURL); + Constants.APK_URL = downloadURL; + MToast.makeTextShort("获取地址成功"); + return; + } + } + MToast.makeTextShort("获取信息错误错误"); + } + }, new Response.ErrorListener() { + @Override + public void onErrorResponse(VolleyError error) { + MProgressDialog.dismissProgress(); + MToast.makeTextShort("错误:"+error.getMessage()); + } + }){ + @Override + protected Map getParams() throws AuthFailureError { + Map params = new HashMap<>(); + params.put("_api_key", "c193c7301fd75ae5a771d8923df6300a"); + params.put("appKey", "bfed5049f2b2c0ce048fd62b015956ac"); + params.put("buildVersion", "1.0.0"); + return params; + } + }; + // Add the request to the RequestQueue. + queue.add(stringRequest); } @Override @@ -194,10 +255,18 @@ public void onClick(View v) { startActivity(new Intent(this, OtherActivity.class)); break; case R.id.btnDownloadBrowser: + if(TextUtils.isEmpty(Constants.APK_URL)){ + Toast.makeText(context,"请先获取最新的下载地址",Toast.LENGTH_SHORT).show(); + return; + } //通过浏览器去下载APK InstallUtils.installAPKWithBrower(this, Constants.APK_URL); break; case R.id.btnDownload: + if(TextUtils.isEmpty(Constants.APK_URL)){ + Toast.makeText(context,"请先获取最新的下载地址",Toast.LENGTH_SHORT).show(); + return; + } //申请SD卡权限 if (!PermissionUtils.isGrantSDCardReadPermission(this)) { PermissionUtils.requestSDCardReadPermission(this, 100); @@ -213,6 +282,9 @@ public void onClick(View v) { .startDownload(); } break; + case R.id.getDownloadUrl: + getAppUpdateInfo(); + break; default: break; } @@ -237,4 +309,5 @@ public long getFileSizes(File f) { return 0; } } + } diff --git a/app/src/main/java/com/maning/mnupdateapk/bean/PgyerAppCheckResultBean.java b/app/src/main/java/com/maning/mnupdateapk/bean/PgyerAppCheckResultBean.java new file mode 100644 index 0000000..d13d48f --- /dev/null +++ b/app/src/main/java/com/maning/mnupdateapk/bean/PgyerAppCheckResultBean.java @@ -0,0 +1,174 @@ +package com.maning.mnupdateapk.bean; + +public class PgyerAppCheckResultBean { + + + private int code; + private String message; + private Data data; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Data getData() { + return data; + } + + public void setData(Data data) { + this.data = data; + } + + public class Data { + + private String buildBuildVersion; + private String forceUpdateVersion; + private String forceUpdateVersionNo; + private boolean needForceUpdate; + private String downloadURL; + private boolean buildHaveNewVersion; + private String buildVersionNo; + private String buildVersion; + private String buildUpdateDescription; + private String appKey; + private String buildKey; + private String buildName; + private String buildIcon; + private String buildFileKey; + private long buildFileSize; + + public String getBuildBuildVersion() { + return buildBuildVersion; + } + + public void setBuildBuildVersion(String buildBuildVersion) { + this.buildBuildVersion = buildBuildVersion; + } + + public String getForceUpdateVersion() { + return forceUpdateVersion; + } + + public void setForceUpdateVersion(String forceUpdateVersion) { + this.forceUpdateVersion = forceUpdateVersion; + } + + public String getForceUpdateVersionNo() { + return forceUpdateVersionNo; + } + + public void setForceUpdateVersionNo(String forceUpdateVersionNo) { + this.forceUpdateVersionNo = forceUpdateVersionNo; + } + + public boolean isNeedForceUpdate() { + return needForceUpdate; + } + + public void setNeedForceUpdate(boolean needForceUpdate) { + this.needForceUpdate = needForceUpdate; + } + + public String getDownloadURL() { + return downloadURL; + } + + public void setDownloadURL(String downloadURL) { + this.downloadURL = downloadURL; + } + + public boolean isBuildHaveNewVersion() { + return buildHaveNewVersion; + } + + public void setBuildHaveNewVersion(boolean buildHaveNewVersion) { + this.buildHaveNewVersion = buildHaveNewVersion; + } + + public String getBuildVersionNo() { + return buildVersionNo; + } + + public void setBuildVersionNo(String buildVersionNo) { + this.buildVersionNo = buildVersionNo; + } + + public String getBuildVersion() { + return buildVersion; + } + + public void setBuildVersion(String buildVersion) { + this.buildVersion = buildVersion; + } + + public String getBuildUpdateDescription() { + return buildUpdateDescription; + } + + public void setBuildUpdateDescription(String buildUpdateDescription) { + this.buildUpdateDescription = buildUpdateDescription; + } + + public String getAppKey() { + return appKey; + } + + public void setAppKey(String appKey) { + this.appKey = appKey; + } + + public String getBuildKey() { + return buildKey; + } + + public void setBuildKey(String buildKey) { + this.buildKey = buildKey; + } + + public String getBuildName() { + return buildName; + } + + public void setBuildName(String buildName) { + this.buildName = buildName; + } + + public String getBuildIcon() { + return buildIcon; + } + + public void setBuildIcon(String buildIcon) { + this.buildIcon = buildIcon; + } + + public String getBuildFileKey() { + return buildFileKey; + } + + public void setBuildFileKey(String buildFileKey) { + this.buildFileKey = buildFileKey; + } + + public long getBuildFileSize() { + return buildFileSize; + } + + public void setBuildFileSize(long buildFileSize) { + this.buildFileSize = buildFileSize; + } + } + + +} diff --git a/app/src/main/java/com/maning/mnupdateapk/Constants.java b/app/src/main/java/com/maning/mnupdateapk/cons/Constants.java similarity index 59% rename from app/src/main/java/com/maning/mnupdateapk/Constants.java rename to app/src/main/java/com/maning/mnupdateapk/cons/Constants.java index 9f582c8..fff99f9 100644 --- a/app/src/main/java/com/maning/mnupdateapk/Constants.java +++ b/app/src/main/java/com/maning/mnupdateapk/cons/Constants.java @@ -1,4 +1,4 @@ -package com.maning.mnupdateapk; +package com.maning.mnupdateapk.cons; import android.os.Environment; @@ -13,7 +13,7 @@ */ public class Constants { - public static final String APK_URL = "https://www.pgyer.com/app/installUpdate/8a6470a9b1cb5efab0fbcabb27fda49a?sig=w6kLobcll%2FfKwM6VjFrtdyy9LGbjobOJGfXxoinLCUgSB6eonijemoYTv2LVhYx8&forceHttps="; + public static String APK_URL = ""; public static final String APK_SAVE_PATH = Environment.getExternalStorageDirectory().getAbsolutePath() + "/MNUpdateAPK/update.apk"; diff --git a/app/src/main/java/com/maning/mnupdateapk/PermissionUtils.java b/app/src/main/java/com/maning/mnupdateapk/utils/PermissionUtils.java similarity index 97% rename from app/src/main/java/com/maning/mnupdateapk/PermissionUtils.java rename to app/src/main/java/com/maning/mnupdateapk/utils/PermissionUtils.java index da303ec..8117624 100644 --- a/app/src/main/java/com/maning/mnupdateapk/PermissionUtils.java +++ b/app/src/main/java/com/maning/mnupdateapk/utils/PermissionUtils.java @@ -1,4 +1,4 @@ -package com.maning.mnupdateapk; +package com.maning.mnupdateapk.utils; import android.Manifest; import android.app.Activity; diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 030b2e0..cce8970 100755 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -9,6 +9,15 @@ android:orientation="vertical" android:padding="10dp"> +