Skip to content

Commit

Permalink
适配N,安装APK在7.0手机出现问题
Browse files Browse the repository at this point in the history
  • Loading branch information
maning committed Apr 5, 2017
1 parent f862d5c commit fd5f78b
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 74 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@

<service android:name="com.amap.api.location.APSService" />

<activity android:name=".ui.activity.CitysActivity"></activity>
<activity android:name=".ui.activity.CitysActivity"/>
</application>

</manifest>
48 changes: 12 additions & 36 deletions app/src/main/java/com/maning/gankmm/ui/activity/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
12 changes: 11 additions & 1 deletion app/src/main/java/com/maning/gankmm/utils/InstallUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/xml/file_provider.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@
<external-path
name="apk2"
path="." />

<external-path
name="GankMM"
path="" />

</paths>
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit fd5f78b

Please sign in to comment.