Commit 4084e879 authored by topjohnwu's avatar topjohnwu

Fix APK installation on old Android versions

parent 8d931dd7
......@@ -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);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment