RemoteModelManager

  • RemoteModelManager is a class used to manage remote models in your Android app, ensuring thread-safe operations.

  • You can use it to download, delete, and check the download status of remote models, including getting a list of all downloaded models of a specific type.

  • Initiating a download with RemoteModelManager handles various scenarios such as ongoing downloads, updates, and errors with specific error codes.

  • You can get an instance of RemoteModelManager using the getInstance() method to start using its functionalities.

  • The class provides methods like deleteDownloadedModel, download, getDownloadedModels, getInstance, and isModelDownloaded for model management.

public class RemoteModelManager extends Object

Manages remote models.

Before using a remote model, download it with RemoteModelManager.

This class is thread safe.

Public Method Summary

Task<Void>
deleteDownloadedModel(RemoteModel remoteModel)
Deletes the given remoteModel from disk.
Task<Void>
download(RemoteModel remoteModel, DownloadConditions downloadConditions)
Initiates the download of remoteModel if the download hasn't begun.
<T extends RemoteModel> Task<Set<T>>
getDownloadedModels(Class<T> modelType)
Returns the set of all currently downloaded models of the given modelType.
synchronized static RemoteModelManager
getInstance()
Gets the RemoteModelManager instance.
Task<Boolean>
isModelDownloaded(RemoteModel remoteModel)
Returns whether the given remoteModel is currently downloaded.

Inherited Method Summary

Public Methods

public Task<Void> deleteDownloadedModel (RemoteModel remoteModel)

Deletes the given remoteModel from disk. Does nothing if the model is not downloaded.

public Task<Void> download (RemoteModel remoteModel, DownloadConditions downloadConditions)

Initiates the download of remoteModel if the download hasn't begun.

If the model's download is already in progress, the current download task will be returned.

If the model is already downloaded to the device, and there is no update, the task will immediately succeed.

If the model is already downloaded to the device, and there is update, a download for the updated version will be attempted.

If the model downloaded failed, the returned Task will contain a MlKitException. Downloads for each type of model may encounter different MlKitException.ErrorCodes. Please check detailed documentation of each RemoteModel class for possible MlKitException.ErrorCodes.

Returns
  • the task for the remoteModel download

public Task<Set<T>> getDownloadedModels (Class<T> modelType)

Returns the set of all currently downloaded models of the given modelType.

public static synchronized RemoteModelManager getInstance ()

Gets the RemoteModelManager instance.

public Task<Boolean> isModelDownloaded (RemoteModel remoteModel)

Returns whether the given remoteModel is currently downloaded.