Skip to main content

3.0.0

General

RuStore In-app updates SDK enable users to be kept up to date with the latest app version on their device. This allows them to stay informed about any performance enhancements or bug fixes that have been implemented.

User scenario example

Additionally, the SDK offers the ability to notify users of a new version and provide an option to install it. The installation process can occur in the background, while the user can track the progress of the update.

See the example app to learn how to integrate Updates SDK correctly.

img

Prerequisites

For RuStore In-app updates SDK to operate correctly, the following conditions need to be met:

  • Android 7.0 or later.
  • RuStore app version on the device is up-to-date.
  • The user is authorized in RuStore
  • RuStore app is allowed to install applications

Connecting to project

Для подключения пакета к проекту выполните следующую команду.

flutter pub add flutter_rustore_update

Эта команда добавит строчку в файл pubspec.yaml.

pubspec.yaml
dependencies:
flutter_rustore_update: ^3.0.0

Проверка наличия обновлений

Before requesting an update, check if it is available for your application To check for updates, call the info() method. When this method is called, the following conditions will be verified:

  • The current version of RuStore is installed on the user's device.
  • The user and the app should not be blocked in RuStore.
  • RuStore app is allowed to install applications.
  • The user is authorized in RuStore.

Upon calling this method, the info object will be returned which contains information regarding any required updates. It is recommended to request and cache this object in advance, ensuring a prompt and convenient update download process for the user.

RustoreUpdateClient.info().then((info) {
print(info);
}).catchError((err) {
print(err);
});
The info object contains a set of parameters needed to determine if an update is available:

  • updateAvailability — update availability:

    :

    • UNKNOWN (int == 0) — by default.;
    • UPDATE_NOT_AVAILABLE (int == 1) — no update required.;
    • UPDATE_AVAILABLE (int == 2) — update needs to be downloaded or it has already been downloaded to the user's device.;
    • DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS (int == 3) — update is already being downloaded or installation is already running..
  • installStatus— update installation status, if the user has already started the update installation at the time:

    :

    • UNKNOWN (int == 0) — by default.;
    • DOWNLOADED (int == 1) — successfully downloaded.;
    • DOWNLOADING (int == 2) — currently being downloaded.;
    • FAILED (int == 3) — error.;
    • PENDING (int == 5) — awaiting update..
info

The update download is only available if the updateAvailability field has the UPDATE_AVAILABLE value.

Скачивание и установка обновлений

Использование слушателя (listener)

Once AppUpdateInfo is received, you can check whether a push update is available.

Проверка статуса скачивания обновления

tip

Silent update requires a separate interface to operate.

Use the listener() method.

RustoreUpdateClient.listener((state) {
switch (state.installStatus) {
case INSTALL_STATUS_DOWNLOADED:
// The update is ready to be installed
break;
case INSTALL_STATUS_DOWNLOADING:
// Here you can display the download progress
break;
case INSTALL_STATUS_FAILED:
print("complete err ${state.installErrorCode}");
break;
}
});

The state object describes the current download status. The object content is below

  • installStatus— update installation status, if the user has already started the update installation at the time:

    :

    • UNKNOWN (int == 0) — by default.;
    • DOWNLOADED (int == 1) — successfully downloaded.;
    • DOWNLOADING (int == 2) — currently being downloaded.;
    • FAILED (int == 3) — error.;
    • PENDING (int == 5) — awaiting update.;
  • bytesDownloaded — number of bytes downloaded.

    ;

  • totalBytesToDownload — total number of bytes that need to be downloaded.

    ;

  • installErrorCode— error code during download. Error structure is described in Error Handling.

Запуск скачивания обновления

Отложенное обновление

Running an upgrade script

Update with RuStore UI

img
  1. To confirm the update, the user is presented with a RuStore UI dialogue.
  2. When you click the Update button, a dialogue box will appear to confirm that the update has been installed.

Running an upgrade script

To start the download, use the download() method.

info

It's important to note that the AppUpdateInfo object becomes obsolete after a single use. To call the startUpdateFlow() method again, request AppUpdateInfo, again using the info() method.

RustoreUpdateClient.download().then((value) {
print("download code ${value.code}");
if (value.code == ACTIVITY_RESULT_CANCELED) {
// The user refused to download
}
}).catchError((err) {
print("download err ${err}");
});

If the user confirmed downloading the update, then resultCode = ACTIVITY_RESULT_OK, if refused, then resultCode = ACTIVITY_RESULT_CANCELED.

Once the INSTALL_STATUS_DOWNLOADED status is received, you can call the complete() method to install the update.

It is advisable to notify the user that the update is prepared for installation at this point.

This method may return an error.

Принудительное обновление

Running an upgrade script

Update with RuStore UI

img
  1. To confirm the update, the user is presented with a RuStore UI dialogue. Until the update is installed, use of the application will be blocked.
  2. When you click the Update button, a dialogue box will appear to confirm that the update has been installed.
  3. If you then click on the 'Install' button, a full-screen dialogue box will appear asking you to install the new app version.
  4. Once the installation is complete, the application will restart.
caution

If the Rustore version is 1.37 or higher, the application will restart. If the version of Rustore is lower, the application will close to install the update. It will not reopen when the update is complete.

Running an upgrade script

To start the download, use the immediate() method.

RustoreUpdateClient.immediate().then((value) {
print("silent code ${value.code}");
}).catchError((err) {
print("immediate err ${err}");
});

resultCode (Int):

  • ACTIVITY_RESULT_OK (-1) — update completed, the code may not be received as the app terminates at the time of update.
  • ACTIVITY_RESULT_CANCELED (0) — flow interrupted by user or an error occurred. When you receive this code, you are expected to exit the app.
  • ACTIVITY_RESULT_NOT_FOUND (2) — RuStore is not installed, or a version that does not support forced updates (RuStore versionCode < < 191).

throwable — error starting update script.

No further action is required if the update is successful.

Тихое обновление

Silent Update Scenario Description

Update without RuStore UI

img

The user will be presented with a dialogue box to confirm the installation of the update (the update will be downloaded in the background).

Running an upgrade script

To start the download, use the silent() method.

RustoreUpdateClient.silent().then((value) {
print("silent code ${value.code}");
}).catchError((err) {
print("silent err ${err}");
});

Calling then with code = ACTIVITY_RESULT_OK will register the task to download the update.

In this scenario, only then can be called with ACTIVITY_RESULT_OK, or catchError.

After calling the method, you can monitor the status of the update download in the listener.

Once the INSTALL_STATUS_DOWNLOADED status is received, you can call the complete() method to install the update. It is advisable to notify the user that the update is prepared for installation at this point.

tip

Silent update requires a separate interface to operate.

Установка обновления

После завершения скачивания файла обновления вы можете запустить установку обновления. Обновление происходит через нативный инструмент Android. Для запуска установки обновления используйте методы:

  • completeUpdateFlexible() — обновление и перезапуск приложения.
  • completeUpdateSilent() — обновление и закрытие приложения.
tip

Рекомендуется уведомить пользователя о готовности обновления к установке.

Гибкое завершение обновления

Вызов метода completeUpdateFlexible
RustoreUpdateClient.completeUpdateFlexible().catchError((err) {
print("completeUpdateFlexible err ${err}");
});

Обновление с UI от RuStore:

img
  1. Пользователю будет показан UI-диалог завершения обновления.

  2. В случае успешного обновления приложение будет перезапущено.

Тихое завершение обновления

Вызов метода completeUpdateSilent
RustoreUpdateClient.completeUpdateSilent().catchError((err) {
print("completeUpdateSilent err ${err}");
});

Обновление без UI от RuStore:

  1. UI-диалог завершения обновления не будет показан.

  2. В случае успешного обновления приложение будет закрыто.

Errors processing

All errors in the plugin are implemented by constants. The constants are described in const.dart.

Список возможных ошибок

  • RuStoreNotInstalledException — RuStore not installed on user's device;
  • RuStoreOutdatedException — RuStore, installed on the user's device, does not support payment processing functions.;
  • RuStoreUserUnauthorizedException — user not authorized on RuStore;
  • RuStoreException — basic RuStore error, from which all other errors are inherited.;
  • RuStoreInstallException(public val code: Int) — download and installation error..
    • ERROR_UNKNOWN(Int = 4001) — unknown error.
    • ERROR_DOWNLOAD(Int = 4002) — error while downloading.
    • ERROR_BLOCKED(Int = 4003) — installation blocked by system.
    • ERROR_INVALID_APK(Int = 4004) — invalid update APK.
    • ERROR_CONFLICT(Int = 4005) — conflict with the current app version.
    • ERROR_STORAGE(Int = 4006) — insufficient device storage.
    • ERROR_INCOMPATIBLE(Int = 4007) — incompatible with device.
    • ERROR_APP_NOT_OWNED(Int = 4008) — application not purchased.
    • ERROR_INTERNAL_ERROR(Int = 4009) — internal error.
    • ERROR_ABORTED(Int = 4010) — user refused to install the update.
    • ERROR_APK_NOT_FOUND(Int = 4011) — APK for installation not found.
    • ERROR_EXTERNAL_SOURCE_DENIED(Int = 4012) — update prohibited. For example, the first method responses that an update is not available, but the user calls the second method.
    • ERROR_ACTIVITY_SEND_INTENT(Int = 9901) — error while sending intent for opening an activity.
    • ERROR_ACTIVITY_UNKNOWN(Int = 9902) — unknown error on activity opening.

Список зависимостей для обновления приложения

  • ru.rustore.sdk:core:0.1.10 — GNU Lesser General Public License v3.0;
  • ru.rustore.sdk:analytics:0.1.5 — GNU Lesser General Public License v3.0;
  • org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.20 — The Apache Software License, Version 2.0;
  • org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4 — The Apache Software License, Version 2.0;
  • androidx.core:core-ktx:1.9.0 — The Apache Software License, Version 2.0;
  • androidx.appcompat:appcompat:1.5.1 — The Apache Software License, Version 2.0;
  • androidx.activity:activity:1.5.1 — The Apache Software License, Version 2.0.