Detectar la actualización de la aplicación de Android y establecer la clase de aplicación booleana para mostrar / ocultar EULA

Estoy intentando detectar cuándo se ha actualizado mi aplicación utilizando un BroadcastReceiver y establecer un valor booleano en mi Clase de aplicación. Este booleano se usará junto con algunos otros booleanos para determinar si se muestra o no el cuadro de diálogo EULA al usuario.

Creo que tengo todo configurado correctamente, pero el CLUF sigue apareciendo cuando no debería. Específicamente, cuando el usuario ya ha aceptado el EULA en una versión anterior, el EULA no ha cambiado en la versión que se está actualizando (configurada manualmente por mí), y la aplicación se está actualizando.

Creo que la razón por la que esto no funciona es porque mi aplicación no se está ejecutando y, por lo tanto, no se llama al método isAppUpgrade () y establece el indicador booleano correcto. ¿Alguien puede confirmar que este es el caso, o hay algo mal en mi código?

FYI - El método estático EULA.show (Activity, boolean, boolean) se llama lo primero en mi actividad Main.

Aquí hay un código

Clase de aplicación

public class MFCApplication extends Application {

    private boolean isUpgrade = false;

    /**
     * Returns a manually set value of whether the EULA has changed in this version of the App
     * @return true/false
     */
    public boolean hasEULAChanged() {
        return false;
    }

    /**
     * Returns whether or not the application has been upgraded.  Set by the UpgradeBroadcastReceiver
     * @return true/false
     */
    public boolean isAppUpgrade() {
        return isUpgrade;
    }

    /**
     * Method called by UpgradeBroadcastReceiver if the App has been upgraded
     */
    public void setAppIsUpgrade() {
        this.isUpgrade = true;
    }
}

Receptor de radiodifusió

public class UpgradeBroadcastReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent == null)
            return;
        if (context == null)
            return;

        String action = intent.getAction();
        if (action == null)
            return;

        if (action.equals(Intent.ACTION_PACKAGE_REPLACED)) {
            MFCApplication myApp = ((MFCApplication)((Activity)context).getApplication());

            myApp.setAppIsUpgrade();
        }
    }
}

EULA Class

public class EULA {

    private static final String EULA_ASSET = "EULA";
    private static final String EULA_PREFERENCES = "eula";
    private static Activity mActivity;

    private static PackageInfo getPackageInfo() {
        PackageInfo pi = null;
        try {
            pi = mActivity.getPackageManager().getPackageInfo(mActivity.getPackageName(), PackageManager.GET_ACTIVITIES);
        } catch (PackageManager.NameNotFoundException ex) {
            ex.printStackTrace();
        }
        return pi;
    }

    public static boolean show(Activity activity, boolean hasEULAChanged, boolean isAppUpgrade) {
        mActivity = activity;
        final SharedPreferences preferences = activity.getSharedPreferences(EULA_PREFERENCES, Activity.MODE_PRIVATE);
        final PackageInfo packageInfo = getPackageInfo();
        String eulaPref = preferences.getString(EULA_PREFERENCES, "0");
        boolean eulaVersionAccepted = packageInfo.versionName.equals(eulaPref);
        if (!eulaVersionAccepted && (hasEULAChanged || !isAppUpgrade)) {
            //The EULA should be shown here, but it isn't
            return false;
        }
        return true;
    }
}

Manifiesto de aplicación

<receiver android:name=".helpers.UpgradeBroadcastReceiver">
    <intent-filter>
        <action android:name="android.intent.action.PACKAGE_REPLACED" />
        <data android:scheme="package" android:path="com.hookedroid.fishingcompanion" />
    </intent-filter>
</receiver>

Respuestas a la pregunta(6)

Su respuesta a la pregunta