I have had this code working for some time now but with Android Orea it doesn't work.
Context context = mContextRef.get();
if (context == null) {
return;
}
// Get the update
String filepath = getDownloadLocation();
File apkFile = new File(filepath);
Uri fileLoc;
Intent intent;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
fileLoc = android.support.v4.content.FileProvider.getUriForFile(context, mFileProviderAuthority, apkFile);
} else {
intent = new Intent(Intent.ACTION_VIEW);
fileLoc = Uri.fromFile(apkFile);
}
intent.setDataAndType(fileLoc, "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(intent);
This code works with all version of android except 8.0 and above.
Edit
Sorry for not explaining more. IT doesn't work meaning, it flashes a window for a fraction of a second and disappears (some times imperceptibly) and continues on in the old app. The file is successfully downloaded (I can navigate to it and install) but when I try to start the activity to install it programmatically it fails with no errors or logs at all.