I am trying to update app after showing the alert dialog in my app. It is working fine below Android Oreo. Here is what I have tried till now
String ANDROID_PACKAGE = "application/vnd.android.package-archive";
File update_apk = new File(context.getFilesDir(), intent.getStringExtra("update_file"));
Intent notificationIntent;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
notificationIntent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
notificationIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
notificationIntent.setDataAndType(
FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".fileprovider", update_apk),
ANDROID_PACKAGE);
} else {
notificationIntent = new Intent(Intent.ACTION_VIEW);
notificationIntent.setDataAndType(
Uri.parse("file://" + update_apk.getAbsolutePath()),
ANDROID_PACKAGE);
}
startActivity(notificationIntent);
How to show this app update dialog in the devices which are not rooted. Any help would be appreciated. Thanks in aadvance.
Check below permission in your manifest.xml file.
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
Also check your file provider for Intent.VIEW_ACTION.
More reference check this page Android install apk with Intent.VIEW_ACTION not working with File provider
enjoy code.