From 4084e8790bd3a6270cb0055f55692d65417f512e Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Tue, 4 Dec 2018 20:27:09 -0500 Subject: [PATCH] Fix APK installation on old Android versions --- .../com/topjohnwu/magisk/utils/APKInstall.java | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/APKInstall.java b/app/src/main/java/com/topjohnwu/magisk/utils/APKInstall.java index 37326a44a..a1740d7a2 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/APKInstall.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/APKInstall.java @@ -11,18 +11,15 @@ import androidx.core.content.FileProvider; public class APKInstall { public static void install(Context c, File apk) { + Intent install = new Intent(Intent.ACTION_INSTALL_PACKAGE); + install.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + install.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - Intent install = new Intent(Intent.ACTION_INSTALL_PACKAGE); - install.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - install.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - Uri content = FileProvider.getUriForFile(c, c.getPackageName() + ".provider", apk); - install.setData(content); - c.startActivity(install); + install.setData(FileProvider.getUriForFile(c, c.getPackageName() + ".provider", apk)); } else { - Intent install = new Intent(Intent.ACTION_VIEW); - install.setDataAndType(Uri.fromFile(apk), "application/vnd.android.package-archive"); - install.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - c.startActivity(install); + apk.setReadable(true, false); + install.setData(Uri.fromFile(apk)); } + c.startActivity(install); } }