La mia app sta cercando di installare un 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);
Nella mia attività
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");
}
Quando la mia INTERTACTIFITRESULT viene licenziata, la mia attività ottiene istantaneamente il codice di risultato 0 che corrisponde a Result_Cancelleld mentre l'interfaccia utente di installazione del sistema è ancora in attesa dell'autorizzazione dell'utente.
La mia attività per conoscere effettivamente se l'installazione ha avuto successo o meno e in base a quell'aggiornamento dell'interfaccia utente.
Qualsiasi aiuto sarà apprezzato.