public final class Metadata


Set of shared metadata fields for Record.

Summary

Constants

static final int

For data actively recorded by the user.

static final int

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

static final int

For data manually entered by the user.

static final int

Unknown recording method.

Public methods

static final @NonNull Metadata

Creates Metadata for an actively recorded record.

static final @NonNull Metadata
activelyRecorded(
    @NonNull Device device,
    @NonNull String clientRecordId,
    long clientRecordVersion
)

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

static final @NonNull Metadata

Creates Metadata to update a record with an existing UUID.

static final @NonNull Metadata

Creates Metadata for an automatically recorded record.

static final @NonNull Metadata
autoRecorded(
    @NonNull Device device,
    @NonNull String clientRecordId,
    long clientRecordVersion
)

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

static final @NonNull Metadata

Creates Metadata to update a record with an existing UUID.

boolean
equals(Object other)
final String

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

final long

Optional client supplied version associated with the data.

final @NonNull DataOrigin

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

final Device

Optional client supplied device information associated with the data.

final @NonNull String

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

final @NonNull Instant

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

final int

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

int
static final @NonNull Metadata

Creates Metadata for a manually entered record.

static final @NonNull Metadata
manualEntry(
    @NonNull String clientRecordId,
    long clientRecordVersion,
    Device device
)

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

static final @NonNull Metadata

Creates Metadata to update a record with an existing UUID.

@NonNull String
static final @NonNull Metadata

Creates Metadata with unknown recording method.

static final @NonNull Metadata
unknownRecordingMethod(
    @NonNull String clientRecordId,
    long clientRecordVersion,
    Device device
)

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

static final @NonNull Metadata

Creates Metadata to update a record with an existing UUID.

Extension functions

final @NonNull Metadata
MetadataTestHelper.populatedWithTestValues(
    @NonNull Metadata receiver,
    @NonNull String id,
    @NonNull DataOrigin dataOrigin,
    @NonNull Instant lastModifiedTime
)

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

Constants

RECORDING_METHOD_ACTIVELY_RECORDED

public static final int RECORDING_METHOD_ACTIVELY_RECORDED = 1

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

public static final int RECORDING_METHOD_AUTOMATICALLY_RECORDED = 2

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

public static final int RECORDING_METHOD_MANUAL_ENTRY = 3

For data manually entered by the user.

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

RECORDING_METHOD_UNKNOWN

public static final int RECORDING_METHOD_UNKNOWN = 0

Unknown recording method.

Public methods

activelyRecorded

Added in 1.1.0-alpha12
public static final @NonNull Metadata activelyRecorded(@NonNull Device device)

Creates Metadata for an actively recorded record.

RECORDING_METHOD_ACTIVELY_RECORDED is auto populated.

Parameters
@NonNull Device device

The Device associated with the record.

activelyRecorded

Added in 1.1.0-alpha12
public static final @NonNull Metadata activelyRecorded(
    @NonNull Device device,
    @NonNull String clientRecordId,
    long clientRecordVersion
)

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

RECORDING_METHOD_ACTIVELY_RECORDED is auto populated.

Parameters
@NonNull Device device

The Device associated with the record.

@NonNull String clientRecordId

The client ID of the record.

long clientRecordVersion

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

activelyRecordedWithId

Added in 1.1.0-alpha12
public static final @NonNull Metadata activelyRecordedWithId(@NonNull String id, @NonNull Device device)

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
@NonNull String id

The existing UUID of the record.

@NonNull Device device

The Device associated with the record.

autoRecorded

Added in 1.1.0-alpha12
public static final @NonNull Metadata autoRecorded(@NonNull Device device)

Creates Metadata for an automatically recorded record.

RECORDING_METHOD_AUTOMATICALLY_RECORDED is auto populated.

Parameters
@NonNull Device device

The Device associated with the record.

autoRecorded

Added in 1.1.0-alpha12
public static final @NonNull Metadata autoRecorded(
    @NonNull Device device,
    @NonNull String clientRecordId,
    long clientRecordVersion
)

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

RECORDING_METHOD_AUTOMATICALLY_RECORDED is auto populated.

Parameters
@NonNull Device device

The Device associated with the record.

@NonNull String clientRecordId

The client ID of the record.

long clientRecordVersion

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

autoRecordedWithId

Added in 1.1.0-alpha12
public static final @NonNull Metadata autoRecordedWithId(@NonNull String id, @NonNull Device device)

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
@NonNull String id

The existing UUID of the record.

@NonNull Device device

The Device associated with the record.

equals

public boolean equals(Object other)

getClientRecordId

Added in 1.1.0-alpha12
public final String getClientRecordId()

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.

getClientRecordVersion

Added in 1.1.0-alpha12
public final long getClientRecordVersion()

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

getDataOrigin

Added in 1.1.0-alpha12
public final @NonNull DataOrigin getDataOrigin()

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.

getDevice

Added in 1.1.0-alpha12
public final Device getDevice()

Optional client supplied device information associated with the data.

getId

Added in 1.1.0-alpha12
public final @NonNull String getId()

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.

getLastModifiedTime

Added in 1.1.0-alpha12
public final @NonNull Instant getLastModifiedTime()

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.

getRecordingMethod

Added in 1.1.0-alpha12
public final int getRecordingMethod()

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.

hashCode

public int hashCode()

manualEntry

Added in 1.1.0-alpha12
public static final @NonNull Metadata manualEntry(Device device)

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

RECORDING_METHOD_MANUAL_ENTRY is auto populated.

Parameters
Device device

The optional Device associated with the record.

manualEntry

Added in 1.1.0-alpha12
public static final @NonNull Metadata manualEntry(
    @NonNull String clientRecordId,
    long clientRecordVersion,
    Device device
)

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
@NonNull String clientRecordId

The client ID of the record.

long clientRecordVersion

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

Device device

The optional Device associated with the record.

manualEntryWithId

Added in 1.1.0-alpha12
public static final @NonNull Metadata manualEntryWithId(@NonNull String id, Device device)

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
@NonNull String id

The existing UUID of the record.

Device device

The optional Device associated with the recording.

toString

public @NonNull String toString()

unknownRecordingMethod

Added in 1.1.0-alpha12
public static final @NonNull Metadata unknownRecordingMethod(Device device)

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

The optional Device associated with the record.

unknownRecordingMethod

Added in 1.1.0-alpha12
public static final @NonNull Metadata unknownRecordingMethod(
    @NonNull String clientRecordId,
    long clientRecordVersion,
    Device device
)

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
@NonNull String clientRecordId

The client ID of the record.

long clientRecordVersion

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

Device device

The optional Device associated with the recording.

unknownRecordingMethodWithId

Added in 1.1.0-alpha12
public static final @NonNull Metadata unknownRecordingMethodWithId(@NonNull String id, Device device)

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
@NonNull String id

The existing UUID of the record.

Device device

The optional Device associated with the record.

Extension functions

MetadataTestHelper.populatedWithTestValues

public final @NonNull Metadata MetadataTestHelper.populatedWithTestValues(
    @NonNull Metadata receiver,
    @NonNull String id,
    @NonNull DataOrigin dataOrigin,
    @NonNull Instant lastModifiedTime
)

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
@NonNull String id

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

@NonNull DataOrigin dataOrigin

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

@NonNull Instant lastModifiedTime

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