AiPackModelProvider

class AiPackModelProvider : ModelProvider

A ModelProvider that's backed by on-demand Google Play AI Pack.

To use this class, you need to declare the following permission in your manifest:

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

NOTE: For install-time AiPack, use ModelProvider.staticModel instead.

Summary

Public constructors

AiPackModelProvider(
    context: Context,
    aiPackName: String,
    modelPath: String,
    vararg accelerators: Accelerator
)
AiPackModelProvider(
    context: Context,
    aiPackName: String,
    modelPath: String,
    acceleratorsProvider: () -> Set<Accelerator>
)
AiPackModelProvider(
    context: Context,
    aiPackName: String,
    modelPath: String,
    accelerators: Set<Accelerator>
)

Public functions

open suspend Unit

Downloads the model if it is not available on the device.

open Set<Accelerator>

Returns the set of accelerators that the model is compatible with.

open String

Returns the absolute path to the model file.

open ModelProvider.Type

It's always a file, for on-demand AiPack.

open Boolean

Returns true if the model is ready to be used.

Inherited functions

From com.google.ai.edge.litert.ModelProvider
open ListenableFuture<Void?>
downloadFuture(lifecycleOwner: LifecycleOwner)

Returns a future that completes when the model is downloaded.

Public constructors

AiPackModelProvider

AiPackModelProvider(
    context: Context,
    aiPackName: String,
    modelPath: String,
    vararg accelerators: Accelerator
)

AiPackModelProvider

AiPackModelProvider(
    context: Context,
    aiPackName: String,
    modelPath: String,
    acceleratorsProvider: () -> Set<Accelerator>
)

AiPackModelProvider

AiPackModelProvider(
    context: Context,
    aiPackName: String,
    modelPath: String,
    accelerators: Set<Accelerator>
)

Public functions

download

open suspend fun download(): Unit

Downloads the model if it is not available on the device.

getCompatibleAccelerators

open fun getCompatibleAccelerators(): Set<Accelerator>

Returns the set of accelerators that the model is compatible with.

getPath

open fun getPath(): String

Returns the absolute path to the model file.

Throws
java.lang.IllegalStateException

if the AiPack is not ready yet.

getType

open fun getType(): ModelProvider.Type

It's always a file, for on-demand AiPack.

isReady

open fun isReady(): Boolean

Returns true if the model is ready to be used.