Fix crash on non-Nougat

This commit is contained in:
topjohnwu 2016-10-19 06:25:50 +08:00
parent e5be8b7f67
commit c854f436bf

View File

@ -5,6 +5,7 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
@ -98,11 +99,18 @@ public class MagiskFragment extends Fragment {
new DownloadReceiver() { new DownloadReceiver() {
@Override @Override
public void task(Uri uri) { public void task(Uri uri) {
Intent install = new Intent(Intent.ACTION_INSTALL_PACKAGE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
install.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); Intent install = new Intent(Intent.ACTION_INSTALL_PACKAGE);
Uri content = FileProvider.getUriForFile(getActivity(), "com.topjohnwu.magisk.provider", new File(uri.getPath())); install.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
install.setData(content); Uri content = FileProvider.getUriForFile(getActivity(), "com.topjohnwu.magisk.provider", new File(uri.getPath()));
mContext.startActivity(install); 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, appLink,