From c854f436bf0e3451245cde1111dc43f719fb3cc2 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Wed, 19 Oct 2016 06:25:50 +0800 Subject: [PATCH] Fix crash on non-Nougat --- .../com/topjohnwu/magisk/MagiskFragment.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/MagiskFragment.java b/app/src/main/java/com/topjohnwu/magisk/MagiskFragment.java index 8cba48ed5..061364e66 100644 --- a/app/src/main/java/com/topjohnwu/magisk/MagiskFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/MagiskFragment.java @@ -5,6 +5,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.net.Uri; import android.os.AsyncTask; +import android.os.Build; import android.os.Bundle; import android.preference.PreferenceManager; import android.support.annotation.Nullable; @@ -98,11 +99,18 @@ public class MagiskFragment extends Fragment { new DownloadReceiver() { @Override public void task(Uri uri) { - Intent install = new Intent(Intent.ACTION_INSTALL_PACKAGE); - install.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - Uri content = FileProvider.getUriForFile(getActivity(), "com.topjohnwu.magisk.provider", new File(uri.getPath())); - install.setData(content); - mContext.startActivity(install); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + Intent install = new Intent(Intent.ACTION_INSTALL_PACKAGE); + install.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + Uri content = FileProvider.getUriForFile(getActivity(), "com.topjohnwu.magisk.provider", new File(uri.getPath())); + install.setData(content); + mContext.startActivity(install); + } else { + Intent install = new Intent(Intent.ACTION_VIEW); + install.setDataAndType(uri, "application/vnd.android.package-archive"); + install.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + mContext.startActivity(install); + } } }, appLink,