ACTION_INSTALL_PACKAGE

My application is trying to install the APK.

Intent installIntent = new Intent(Intent.ACTION_INSTALL_PACKAGE); installIntent.setData(Uri.fromFile(new File(pathToApk))); installIntent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true); installIntent.putExtra(Intent.EXTRA_RETURN_RESULT, true); installIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); ((Activity)context).startActivityForResult(installIntent, Constants.APP_INSTALL_REQUEST); 

In my work

 protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case Constants.APP_INSTALL_REQUEST: if(resultCode == RESULT_OK){ Log.e(TAG, "Package Installation Success"); }else if(resultCode == RESULT_FIRST_USER){ Log.e(TAG, "Package Installation Cancelled by USER"); }else{ Log.e(TAG, "Something went wrong - INSTALLATION FAILED"); } 

When my startActivityResult is started, my activity instantly gets a result code 0 that corresponds to RESULT_CANCELLED, while the system setup user interface is still waiting for user permission.

enter image description here

My activity is to find out if the installation was successful or not, and based on this update of its user interface.

Any help would be appreciated.

+6
source share
1 answer

Found the culprit.

* installIntent.setFlags (Intent.FLAG_ACTIVITY_NEW_TASK); *

Although the system returns a real instance of my activity, it is on the new TASK stack . Thus, the system cancels actionForResult before it launches a new TASK.

thanks

+7
source

Source: https://habr.com/ru/post/957551/


All Articles