how to detect if user clicked done or open after application in android has been installed programmatically

Following These Steps:

  • You are trying to programatically install a APK
  • You need to get the status, whether the user pressed buttons Open or Done, after the successful installation.

This can be done. For this, start the package installer like this.

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File("Full path to your APK")),"application/vnd.android.package-archive"); // the APK path can be in SDCARD or in your application directory..
// start the package-installer activity and wait for result. The second parameter can be used to identify the source of result in `onActivityResult` method.
startActivityForResult(intent, 1);
  • Now the package installer will be started and your APK will get installed on device.
  • User presses either Open or Done buttons.
  • You gets the program control back in onActivityResult callback function
    Here goes the onActivityResult function:
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // requestCode == 1 means the result for package-installer activity
        if (requestCode == 1)
        {
            // resultCode == RESULT_CANCELED means user pressed `Done` button
            if (resultCode == RESULT_CANCELED) {
            Toast.makeText(this, "User pressed 'Done' button", Toast.LENGTH_SHORT);
            }
            else if (resultCode == RESULT_OK) {
                // resultCode == RESULT_OK means user pressed `Open` button
                Toast.makeText(this, "User pressed 'Open' button", Toast.LENGTH_SHORT);
            }
        }
        super.onActivityResult(requestCode, resultCode, data);
    }