Force updating Android app version with Firebase RemoteConfig not working always

Viewed 568

I am working on an Android application with around 3000 daily activity users.

We have an option to force the update of the app, using the Firebase RemoteConfig. If we think that the minimum version should be, for example, 1.62, we change the remote parameter of Firebase and if the user has an older version, a Dialog appears at the beginning of the session, forcing the user to go to the Play Store and updating the app.

It's working on most of the cases, but around 1% of the users are able to use the app without seeing that Dialog. I tried to reproduce the problem several times, but I have not been able to, the Dialog always appears to me if I have a buildVersion older than the required.

Here is the code related to this:

In the onCreate() of the MainActivity, after checking if the user has connectivity (we don't allow the use of the app if the user doesn't have connectivity)...

    /**
     * Initializes RemoteConfig for the project. If the connection with the remote config server
     * is successfully, starts checkVersionUpdate().
     */
    fun initRemoteConfig() {
        val firebaseRemoteConfig = FirebaseRemoteConfig.getInstance()
        val remoteConfigDefaults: MutableMap<String, Any> = HashMap()
        firebaseRemoteConfig.setDefaultsAsync(remoteConfigDefaults)
        firebaseRemoteConfig.fetch(IMMEDIATE_FETCH).addOnCompleteListener {
            if (it.isSuccessful) {
                firebaseRemoteConfig.activate().addOnCompleteListener { it2 ->
                    if (it2.isSuccessful) {
                        checkVersionUpdate()
                    }
                }
            }
        }
    }

The checkVersionUpdate() method, the parameter update_required has been always true...

    /**
     * Checks if there is a new version of SagaCollect available, if its true, forces the
     * user to download it, otherwise opens LoginFragment.
     */
    private fun checkVersionUpdate() {
        val firebaseRemoteConfig = FirebaseRemoteConfig.getInstance()
        val remoteVersionUpdate = firebaseRemoteConfig.getString(Constants.KEY_CURRENT_VERSION)
        val result = VersionUtils.needsUpdate(BuildConfig.VERSION_NAME, remoteVersionUpdate) &&
                firebaseRemoteConfig.getBoolean(Constants.KEY_UPDATE_REQUIRED)
        if (result && !mainView.isFinishing) {
            mainView.showNewVersionAvailable()
        } else {
            mainView.openLogin()
        }
    }

And the needsUpdate() method, the catch only happens around two or three times per day...

public static boolean needsUpdate(final String currentVersion, final String serverVersion) {
        boolean result;
        try {
            final String[] preparedCurrentVersion = currentVersion.split(DOT);
            final String[] preparedServerVersion = serverVersion.split(DOT);
            final int leftNumberCurrentVersion = Integer.parseInt(preparedCurrentVersion[LEFT]);
            final int leftNumberServerVersion = Integer.parseInt(preparedServerVersion[LEFT]);
            final int rightNumberCurrentVersion = Integer.parseInt(preparedCurrentVersion[RIGHT]);
            final int rightNumberServerVersion = Integer.parseInt(preparedServerVersion[RIGHT]);
            result = leftNumberServerVersion > leftNumberCurrentVersion ||
                    (leftNumberServerVersion == leftNumberCurrentVersion &&
                            rightNumberServerVersion > rightNumberCurrentVersion);
        } catch (final Exception e) {
            result = true
        }
        return result;
}

Any idea on how users could be entering the app and being able to open Login and continue with the session? We have events and we know that they open the app, so they surely pass by the onCreate() of the MainActivity.

Thank you so much.

Cheers, Mauricio

0 Answers
Related