0

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
  • "the app crashes" -- use Logcat to examine the stack trace associated with your crash: https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this – CommonsWare Jul 16 '20 at 10:50
  • No error in Logcat.. The app installs in the background. Like this question explains: : Install an updated apk on Android 10 devices and put the same app in foreground – Shaheryar Khan Jul 17 '20 at 05:31
  • "No error in Logcat" -- then either your app is not crashing or you are not using Logcat correctly. – CommonsWare Jul 17 '20 at 10:58
  • Its also confusing for me, but this is happening. The app installs the update and it shows the message that BroadcastQueue: Background execution not allowed and it receives the intents and updates. – Shaheryar Khan Jul 17 '20 at 11:27

0 Answers0