class Metadata


Set of shared metadata fields for Record.

Summary

Constants

const Int

For data actively recorded by the user.

const Int

For data recorded passively by a device without user explicitly initiating the recording, or whenever it cannot be determined.

const Int

For data manually entered by the user.

const Int

Unknown recording method.

Public companion functions

Metadata

Creates Metadata for an actively recorded record.

Metadata
activelyRecorded(
    device: Device,
    clientRecordId: String,
    clientRecordVersion: Long
)

Creates Metadata for an actively recorded record with the provided client ID.

Metadata

Creates Metadata to update a record with an existing UUID.

Metadata

Creates Metadata for an automatically recorded record.

Metadata
autoRecorded(
    device: Device,
    clientRecordId: String,
    clientRecordVersion: Long
)

Creates Metadata for an automatically recorded record with the provided client ID.

Metadata

Creates Metadata to update a record with an existing UUID.

Metadata
manualEntry(device: Device?)

Creates Metadata for a manually entered record.

Metadata
manualEntry(
    clientRecordId: String,
    clientRecordVersion: Long,
    device: Device?
)

Creates Metadata for a manually entered record with the provided client ID.

Metadata
manualEntryWithId(id: String, device: Device?)

Creates Metadata to update a record with an existing UUID.

Metadata

Creates Metadata with unknown recording method.

Metadata
unknownRecordingMethod(
    clientRecordId: String,
    clientRecordVersion: Long,
    device: Device?
)

Creates Metadata with unknown recording method with the provided client ID.

Metadata

Creates Metadata to update a record with an existing UUID.

Public functions

open operator Boolean
equals(other: Any?)
open Int
open String

Public properties

String?

Optional client supplied record unique data identifier associated with the data.

Long

Optional client supplied version associated with the data.

DataOrigin

Where the data comes from, such as application information originally generated this data.

Device?

Optional client supplied device information associated with the data.

String

Unique identifier of this data, assigned by the Android Health Platform at insertion time.

Instant

Automatically populated to when data was last modified (or originally created).

Int

Client supplied data recording method to help to understand how the data was recorded.

Extension functions

Metadata
Metadata.populatedWithTestValues(
    id: String,
    dataOrigin: DataOrigin,
    lastModifiedTime: Instant
)

Creates a new Metadata object by copying existing fields and overriding id, dataOrigin, and lastModifiedTime for testing purposes.

Constants

RECORDING_METHOD_ACTIVELY_RECORDED

const val RECORDING_METHOD_ACTIVELY_RECORDED = 1: Int

For data actively recorded by the user.

For e.g. An exercise session actively recorded by the user using a phone or a watch device.

device must be specified when using this recording method.

RECORDING_METHOD_AUTOMATICALLY_RECORDED

const val RECORDING_METHOD_AUTOMATICALLY_RECORDED = 2: Int

For data recorded passively by a device without user explicitly initiating the recording, or whenever it cannot be determined.

For e.g. Steps data recorded by a watch or phone without the user starting a session.

device must be specified when using this recording method.

RECORDING_METHOD_MANUAL_ENTRY

const val RECORDING_METHOD_MANUAL_ENTRY = 3: Int

For data manually entered by the user.

For e.g. Nutrition or weight data entered by the user.

RECORDING_METHOD_UNKNOWN

const val RECORDING_METHOD_UNKNOWN = 0: Int

Unknown recording method.

Public companion functions

activelyRecorded

Added in 1.1.0-alpha12
fun activelyRecorded(device: Device): Metadata

Creates Metadata for an actively recorded record.

RECORDING_METHOD_ACTIVELY_RECORDED is auto populated.

Parameters
device: Device

The Device associated with the record.

activelyRecorded

Added in 1.1.0-alpha12
fun activelyRecorded(
    device: Device,
    clientRecordId: String,
    clientRecordVersion: Long = 0
): Metadata

Creates Metadata for an actively recorded record with the provided client ID.

RECORDING_METHOD_ACTIVELY_RECORDED is auto populated.

Parameters
device: Device

The Device associated with the record.

clientRecordId: String

The client ID of the record.

clientRecordVersion: Long = 0

The client version of the record (default: 0).

activelyRecordedWithId

Added in 1.1.0-alpha12
fun activelyRecordedWithId(id: String, device: Device): Metadata

Creates Metadata to update a record with an existing UUID.

RECORDING_METHOD_ACTIVELY_RECORDED is auto populated.

Use this only when there's no client ID or version associated with the record.

Parameters
id: String

The existing UUID of the record.

device: Device

The Device associated with the record.

autoRecorded

Added in 1.1.0-alpha12
fun autoRecorded(device: Device): Metadata

Creates Metadata for an automatically recorded record.

RECORDING_METHOD_AUTOMATICALLY_RECORDED is auto populated.

Parameters
device: Device

The Device associated with the record.

autoRecorded

Added in 1.1.0-alpha12
fun autoRecorded(
    device: Device,
    clientRecordId: String,
    clientRecordVersion: Long = 0
): Metadata

Creates Metadata for an automatically recorded record with the provided client ID.

RECORDING_METHOD_AUTOMATICALLY_RECORDED is auto populated.

Parameters
device: Device

The Device associated with the record.

clientRecordId: String

The client ID of the record.

clientRecordVersion: Long = 0

The client version of the record (default: 0).

autoRecordedWithId

Added in 1.1.0-alpha12
fun autoRecordedWithId(id: String, device: Device): Metadata

Creates Metadata to update a record with an existing UUID.

RECORDING_METHOD_AUTOMATICALLY_RECORDED is auto populated.

Use this only when there's no client ID or version associated with the record.

Parameters
id: String

The existing UUID of the record.

device: Device

The Device associated with the record.

manualEntry

Added in 1.1.0-alpha12
fun manualEntry(device: Device? = null): Metadata

Creates Metadata for a manually entered record. Developers can provide optional device information.

RECORDING_METHOD_MANUAL_ENTRY is auto populated.

Parameters
device: Device? = null

The optional Device associated with the record.

manualEntry

Added in 1.1.0-alpha12
fun manualEntry(
    clientRecordId: String,
    clientRecordVersion: Long = 0,
    device: Device? = null
): Metadata

Creates Metadata for a manually entered record with the provided client ID. Developers can provide optional device information.

RECORDING_METHOD_MANUAL_ENTRY is auto populated.

Parameters
clientRecordId: String

The client ID of the record.

clientRecordVersion: Long = 0

The client version of the record (default: 0).

device: Device? = null

The optional Device associated with the record.

manualEntryWithId

Added in 1.1.0-alpha12
fun manualEntryWithId(id: String, device: Device? = null): Metadata

Creates Metadata to update a record with an existing UUID.

RECORDING_METHOD_MANUAL_ENTRY is auto populated.

Use this only when there's no client ID or version associated with the record.

Parameters
id: String

The existing UUID of the record.

device: Device? = null

The optional Device associated with the recording.

unknownRecordingMethod

Added in 1.1.0-alpha12
fun unknownRecordingMethod(device: Device? = null): Metadata

Creates Metadata with unknown recording method.

RECORDING_METHOD_UNKNOWN is auto populated.

This should only be used in the case when the recording method is geniously unknown.

Parameters
device: Device? = null

The optional Device associated with the record.

unknownRecordingMethod

Added in 1.1.0-alpha12
fun unknownRecordingMethod(
    clientRecordId: String,
    clientRecordVersion: Long = 0,
    device: Device? = null
): Metadata

Creates Metadata with unknown recording method with the provided client ID.

RECORDING_METHOD_UNKNOWN is auto populated.

This should only be used in the case when the recording method is geniously unknown.

Parameters
clientRecordId: String

The client ID of the record.

clientRecordVersion: Long = 0

The client version of the record (default: 0).

device: Device? = null

The optional Device associated with the recording.

unknownRecordingMethodWithId

Added in 1.1.0-alpha12
fun unknownRecordingMethodWithId(id: String, device: Device? = null): Metadata

Creates Metadata to update a record with an existing UUID.

RECORDING_METHOD_UNKNOWN is auto populated.

This should only be used in the case when the recording method is geniously unknown.

Parameters
id: String

The existing UUID of the record.

device: Device? = null

The optional Device associated with the record.

Public functions

equals

open operator fun equals(other: Any?): Boolean

hashCode

open fun hashCode(): Int

toString

open fun toString(): String

Public properties

clientRecordId

Added in 1.1.0-alpha12
val clientRecordIdString?

Optional client supplied record unique data identifier associated with the data.

There is guaranteed a single entry for any type of data with same client provided identifier for a given client. Any new insertions with the same client provided identifier will either replace or be ignored depending on associated clientRecordVersion.

clientRecordVersion

Added in 1.1.0-alpha12
val clientRecordVersionLong

Optional client supplied version associated with the data.

This determines conflict resolution outcome when there are multiple insertions of the same clientRecordId. Data with the highest clientRecordVersion takes precedence. clientRecordVersion starts with 0.

See also
clientRecordId

dataOrigin

Added in 1.1.0-alpha12
val dataOriginDataOrigin

Where the data comes from, such as application information originally generated this data. When Record is created before insertion, this contains a sentinel value, any assigned value will be ignored. After insertion, this will be populated with inserted application.

device

Added in 1.1.0-alpha12
val deviceDevice?

Optional client supplied device information associated with the data.

id

Added in 1.1.0-alpha12
val idString

Unique identifier of this data, assigned by the Android Health Platform at insertion time. When Record is created before insertion, this takes a sentinel value, any assigned value will be ignored.

lastModifiedTime

Added in 1.1.0-alpha12
val lastModifiedTimeInstant

Automatically populated to when data was last modified (or originally created). When Record is created before inserted, this contains a sentinel value, any assigned value will be ignored.

recordingMethod

Added in 1.1.0-alpha12
val recordingMethodInt

Client supplied data recording method to help to understand how the data was recorded.

It should be one of the following: RECORDING_METHOD_UNKNOWN, RECORDING_METHOD_ACTIVELY_RECORDED, RECORDING_METHOD_AUTOMATICALLY_RECORDED and RECORDING_METHOD_MANUAL_ENTRY.

Extension functions

populatedWithTestValues

fun Metadata.populatedWithTestValues(
    id: String = "",
    dataOrigin: DataOrigin = DataOrigin(""),
    lastModifiedTime: Instant = Instant.EPOCH
): Metadata

Creates a new Metadata object by copying existing fields and overriding id, dataOrigin, and lastModifiedTime for testing purposes.

This simulates the behavior of the Health Connect implementation, which automatically populates these values during record insertion.

Parameters
id: String = ""

The ID to assign to the new Metadata. Defaults to an empty string.

dataOrigin: DataOrigin = DataOrigin("")

The DataOrigin to assign to the new Metadata. Defaults to a DataOrigin with an empty package name.

lastModifiedTime: Instant = Instant.EPOCH

The Instant representing the last modified time. Defaults to Instant.EPOCH.