ACTION_INSTALL_PACKAGE
Asked Answered
C

1

11

My app is trying to install an 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 Activity

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 fired my activity instantly gets the result code 0 which corresponds to RESULT_CANCELLED while the System Install UI is still waiting for the user permission.

enter image description here

My activity to actually get to know whether the installation was successful or not and based on that update its UI.

Any help wud be appreciated.

Cultured answered 7/11, 2013 at 0:19 Comment(1)
Note that EXTRA_NOT_UNKNOWN_SOURCE is having no effect and can be removed: code.google.com/p/android/issues/detail?id=42253Ribose
C
15

Found the culprit.

*installIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);*

Though the system brings the existing instance of my activity back to life it is in the new TASK stack. So the system cancels the activityForResult before it starts the new TASK.

Thank you

Cultured answered 7/11, 2013 at 1:7 Comment(2)
please accept your own answer, so that it goes off the list of "unanswered questions"Genoese
Cant do it until it is 2 daysCultured

© 2022 - 2024 — McMap. All rights reserved.