Customization

There are a few ways to customize the user experience based on your choice: UpdateManager or AutoUpdateManager.

AutoUpdateManager

There are only one option open for customization here. You can select between FLEXIBLE & IMMEDIATE update.

Flexible Update:

A user experience that provides background download and installation with graceful state monitoring. This UX is appropriate when it’s acceptable for the user to use the app while downloading the update. For example, you want to urge users to try a new feature that’s not critical to the core functionality of your app.

Immediate Update:

A full screen user experience that requires the user to update and restart the app in order to continue using the app. This UX is best for cases where an update is critical for continued use of the app. After a user accepts an immediate update, Google Play handles the update installation and app restart.

UpdateManager

If you prefer to customize that experience this is the place for you! You have quiet more options to tweak based on your needs here.

First of all and most important thing, do not forget to call CheckForAnUpdate() function after the initialization! Let's create a basic class with customization:

public class CustomUpdater : MonoBehaviour {

        private AndroidUpdateManager _updateManager;
        
        
        private void Start () {
            // Initialize the AndroidUpdateManager variable
            _updateManager = GetComponent<AndroidUpdateManager> ();
            // If you set onStartCheck = true in AndroidUpdateManager
            // from Unity Editor, you can remove the next line since
            // it will be called by default in Start function.
            // However if you want to call this in another place, like Button click
            // or somewhere else, you have to be sure that it's called
            // once AndroidUpdateManager is initialized!
            _updateManager.CheckForAnUpdate ();
        }
}

The next step is to subscribe for events which we want to customize:

        private void OnEnable () {
            // Once we got response from Google's Play Core library
            // this event will be triggered with information about
            // available version code.
            AndroidUpdateManager.OnUpdateAvailable += OnUpdateAvailable;
        }

        private void OnDisable () {
            // Do not forget to unsubscribe
            AndroidUpdateManager.OnUpdateAvailable -= OnUpdateAvailable;
        }
        
        private void OnUpdateAvailable (int availableVersionCode) {
            // Here we can inform the user about the update.
            // Maybe show a dialog and based on his desicion start
            // the update process by calling:
            _updateManager.StartUpdate ();
        }

You can monitor to download progress by subscribing for an event:

       private void OnEnable () {
            AndroidUpdateManager.OnUpdateDownloading += OnUpdateDownloading;
        }

        private void OnDisable () {
            AndroidUpdateManager.OnUpdateDownloading -= OnUpdateDownloading;
        }

        private void OnUpdateDownloading (long bytesDownloaded, long totalBytesToDownload) {
            // We can show an image progress to inform
            // the user about the downloading process.
        }

Once the download complete an event will be triggered:

       private void OnEnable () {
            AndroidUpdateManager.OnUpdateDownloaded += OnUpdateDownloaded;
        }

        private void OnDisable () {
            AndroidUpdateManager.OnUpdateDownloaded -= OnUpdateDownloaded;
        }

        private void OnUpdateDownloaded () {
            // Update is downloaded and ready to install
            // Here is the place where you can check if the user
            // is in the middle of a race / level and etc
            // and let him know that the update is downloaded.
            // Based on his/her decision you can call CompleteUpdate
            // to start the installation / updating process.
            _updateManager.CompleteUpdate ();
        }

If you want to receive information about the update state, you can subscribe to another event:

        private void OnEnable () {
            AndroidUpdateManager.OnStateUpdate += OnStateUpdated;
        }

        private void OnDisable () {
            AndroidUpdateManager.OnStateUpdate -= OnStateUpdated;
        }

        private void OnStateUpdated (int install) {
            // You can cache an information about the current state of the update
            // and based on install variable to show the user
            // an information about the current progress
        }

Here are the available install statuses:

        // Unknown status
        UNKNOWN = 0,
        // Pending, which means that the update is scheduled
        // This will be posted if the user selects to wait for Wifi
        // in order to download the update or there is already another
        // update process running (another app is updated by Play Store)
        PENDING = 1,
        // Downloading the update
        DOWNLOADING = 2,
        // Installing the downloaded update
        INSTALLING = 3,
        // The update is installed
        INSTALLED = 4,
        // The update process failed for a reason
        FAILED = 5,
        // The update is canceled
        CANCELED = 6,
        // Update is downloaded
        DOWNLOADED = 11

If the update fails, you can receive an additional information about the issue by subscribing for...yes, you guessed right, another event!

        private void OnEnable () {
            AndroidUpdateManager.OnErrorReceived+= OnErrorReceived;
        }

        private void OnDisable () {
            AndroidUpdateManager.OnErrorReceived-= OnErrorReceived;
        }

        private void OnErrorReceived(string errorMessage) {
            // Here you will receive more information about
            // the error which was thrown
        }

And I guess that's all! : )

Last updated