diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 3db61c5..04504ee 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -261,7 +261,7 @@
-
+
\ No newline at end of file
diff --git a/app/src/main/java/com/maning/gankmm/ui/activity/MainActivity.java b/app/src/main/java/com/maning/gankmm/ui/activity/MainActivity.java
index 42eec09..01f93eb 100644
--- a/app/src/main/java/com/maning/gankmm/ui/activity/MainActivity.java
+++ b/app/src/main/java/com/maning/gankmm/ui/activity/MainActivity.java
@@ -466,72 +466,48 @@ private void showDownloadDialog(AppUpdateInfo appUpdateInfo) {
.title("正在下载最新版本")
.content("请稍等")
.canceledOnTouchOutside(false)
+ .cancelable(false)
.progress(false, 100, false)
- .cancelListener(new DialogInterface.OnCancelListener() {
- @Override
- public void onCancel(final DialogInterface dialog) {
- if (dialogUpdate.isCancelled()) {
- return;
- }
- dialogCloseWarn = DialogUtils.showMyDialog(MainActivity.this, "警告", "当前正在下载APK,是否关闭进度框?", "关闭", "取消", new DialogUtils.OnDialogClickListener() {
- @Override
- public void onConfirm() {
- dialog.dismiss();
- }
-
- @Override
- public void onCancel() {
-
- }
- });
- }
- })
.show();
new InstallUtils(context, appUpdateInfo.getInstall_url(), Constants.UpdateAPKPath, "GankMM_" + appUpdateInfo.getVersionShort(), new InstallUtils.DownloadCallBack() {
@Override
public void onStart() {
KLog.i("onStart");
- if (dialogUpdate.isCancelled()) {
- return;
+ if (dialogUpdate != null) {
+ dialogUpdate.setProgress(0);
}
- dialogUpdate.setProgress(0);
}
@Override
public void onComplete(String path) {
KLog.i("onComplete:" + path);
- if (dialogCloseWarn != null) {
+ InstallUtils.installAPK(context, path);
+ if (dialogCloseWarn != null && dialogCloseWarn.isShowing()) {
dialogCloseWarn.dismiss();
}
- if (dialogUpdate.isCancelled()) {
- return;
+ if (dialogUpdate != null && dialogUpdate.isShowing()) {
+ dialogUpdate.dismiss();
}
- dialogUpdate.dismiss();
- //安装APK
- InstallUtils.installAPK(context, path);
}
@Override
public void onLoading(long total, long current) {
KLog.i("onLoading:-----total:" + total + ",current:" + current);
- if (dialogUpdate.isCancelled()) {
- return;
+ if (dialogUpdate != null) {
+ dialogUpdate.setProgress((int) (current * 100 / total));
}
- dialogUpdate.setProgress((int) (current * 100 / total));
}
@Override
public void onFail(Exception e) {
- if (dialogCloseWarn != null) {
+ if (dialogCloseWarn != null && dialogCloseWarn.isShowing()) {
dialogCloseWarn.dismiss();
}
- if (dialogUpdate.isCancelled()) {
- return;
+ if (dialogUpdate != null && dialogUpdate.isShowing()) {
+ dialogUpdate.dismiss();
}
- dialogUpdate.dismiss();
}
-
}).downloadAPK();
}
diff --git a/app/src/main/java/com/maning/gankmm/ui/activity/SettingActivity.java b/app/src/main/java/com/maning/gankmm/ui/activity/SettingActivity.java
index 95608b9..473cbf7 100644
--- a/app/src/main/java/com/maning/gankmm/ui/activity/SettingActivity.java
+++ b/app/src/main/java/com/maning/gankmm/ui/activity/SettingActivity.java
@@ -270,71 +270,48 @@ private void showDownloadDialog(AppUpdateInfo appUpdateInfo) {
.title("正在下载最新版本")
.content("请稍等")
.canceledOnTouchOutside(false)
+ .cancelable(false)
.progress(false, 100, false)
- .cancelListener(new DialogInterface.OnCancelListener() {
- @Override
- public void onCancel(final DialogInterface dialog) {
- if (dialogUpdate.isCancelled()) {
- return;
- }
- dialogCloseWarn = DialogUtils.showMyDialog(SettingActivity.this, "警告", "当前正在下载APK,是否关闭进度框?", "关闭", "取消", new DialogUtils.OnDialogClickListener() {
- @Override
- public void onConfirm() {
- dialog.dismiss();
- }
-
- @Override
- public void onCancel() {
-
- }
- });
- }
- })
.show();
new InstallUtils(context, appUpdateInfo.getInstall_url(), Constants.UpdateAPKPath, "GankMM_" + appUpdateInfo.getVersionShort(), new InstallUtils.DownloadCallBack() {
@Override
public void onStart() {
KLog.i("onStart");
- if (dialogUpdate.isCancelled()) {
- return;
+ if (dialogUpdate != null) {
+ dialogUpdate.setProgress(0);
}
- dialogUpdate.setProgress(0);
}
@Override
public void onComplete(String path) {
KLog.i("onComplete:" + path);
InstallUtils.installAPK(context, path);
- if (dialogCloseWarn != null) {
+ if (dialogCloseWarn != null && dialogCloseWarn.isShowing()) {
dialogCloseWarn.dismiss();
}
- if (dialogUpdate.isCancelled()) {
- return;
+ if (dialogUpdate != null && dialogUpdate.isShowing()) {
+ dialogUpdate.dismiss();
}
- dialogUpdate.dismiss();
}
@Override
public void onLoading(long total, long current) {
KLog.i("onLoading:-----total:" + total + ",current:" + current);
- if (dialogUpdate.isCancelled()) {
- return;
+ if (dialogUpdate != null) {
+ dialogUpdate.setProgress((int) (current * 100 / total));
}
- dialogUpdate.setProgress((int) (current * 100 / total));
}
@Override
public void onFail(Exception e) {
- if (dialogCloseWarn != null) {
+ if (dialogCloseWarn != null && dialogCloseWarn.isShowing()) {
dialogCloseWarn.dismiss();
}
- if (dialogUpdate.isCancelled()) {
- return;
+ if (dialogUpdate != null && dialogUpdate.isShowing()) {
+ dialogUpdate.dismiss();
}
- dialogUpdate.dismiss();
}
-
}).downloadAPK();
}
diff --git a/app/src/main/java/com/maning/gankmm/utils/InstallUtils.java b/app/src/main/java/com/maning/gankmm/utils/InstallUtils.java
index 1f6fda2..fc956a3 100644
--- a/app/src/main/java/com/maning/gankmm/utils/InstallUtils.java
+++ b/app/src/main/java/com/maning/gankmm/utils/InstallUtils.java
@@ -4,6 +4,8 @@
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
+import android.os.Build;
+import android.support.v4.content.FileProvider;
import android.text.TextUtils;
import java.io.File;
@@ -178,8 +180,16 @@ private void destroyTimer() {
public static void installAPK(Context context, String filePath) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
- intent.setDataAndType(Uri.parse("file://" + filePath), "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ File apkFile = new File(filePath);
+ intent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive");
+// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+// intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
+// Uri contentUri = FileProvider.getUriForFile(context, "com.maning.gankmm.fileProvider", apkFile);
+// intent.setDataAndType(contentUri, "application/vnd.android.package-archive");
+// } else {
+// intent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive");
+// }
context.startActivity(intent);
}
diff --git a/app/src/main/res/xml/file_provider.xml b/app/src/main/res/xml/file_provider.xml
index 88777b9..8b48b6c 100644
--- a/app/src/main/res/xml/file_provider.xml
+++ b/app/src/main/res/xml/file_provider.xml
@@ -6,4 +6,9 @@
+
+
+
\ No newline at end of file
diff --git a/build.gradle b/build.gradle
index d0920fa..f1d1abb 100644
--- a/build.gradle
+++ b/build.gradle
@@ -32,8 +32,8 @@ ext {
buildToolsVersion = "25.0.2"
minSdkVersion = 16
targetSdkVersion = 25
- versionCode = 16
- versionName = "1.5.1"
+ versionCode = 15
+ versionName = "1.5.0"
storePassword = "123456"
keyAlias = "Gank"
keyPassword = "123456"