Similar Question on: Install an updated apk on Android 10 devices and put the same app in foreground
I am using the Package Installer for updating my App. The Apk is stored on a server and the app automatically downloads it if an update is available. The Apk is downloading fine and the app is also updated in the background. However, the app crashes in the onNewIntent function when it last receives the status message of PackageInstaller.STATUS_PENDING_USER_ACTION.
The app should show the installation process but it crashes. However, on starting the app again it has been updated.
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Bundle extras = intent.getExtras();
if (PACKAGE_INSTALLED_ACTION.equals(intent.getAction())) {
int status = extras.getInt(PackageInstaller.EXTRA_STATUS);
String message = extras.getString(PackageInstaller.EXTRA_STATUS_MESSAGE);
Log.i("shaheryar", "Status is:" + status);
switch (status) {
case PackageInstaller.STATUS_PENDING_USER_ACTION:
Intent confirmIntent = (Intent) extras.get(Intent.EXTRA_INTENT);
startActivity(confirmIntent);
break;
case PackageInstaller.STATUS_SUCCESS:
updateView.setVisibility(View.GONE);
navigateToLoginScreen();
break;
case PackageInstaller.STATUS_FAILURE:
break;
case PackageInstaller.STATUS_FAILURE_ABORTED:
case PackageInstaller.STATUS_FAILURE_BLOCKED:
break;
case PackageInstaller.STATUS_FAILURE_CONFLICT:
break;
case PackageInstaller.STATUS_FAILURE_INCOMPATIBLE:
break;
case PackageInstaller.STATUS_FAILURE_INVALID:
break;
case PackageInstaller.STATUS_FAILURE_STORAGE:
break;
default:
Toast.makeText(this, "Unrecognized status received from installer: " + status,
Toast.LENGTH_SHORT).show();
}
}
}```
P.S. Additional Info: (If I run the app on my emulator by simply running it shows that there is a problem in signing certificate which is true as the Apk on the server is release while app runs on emulator Is debug). Which means that it returns back to newIntent function is there is Install conflict