Metadata
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 |
activelyRecorded(@NonNull Device device)Creates Metadata for an actively recorded record. |
static final @NonNull Metadata |
activelyRecorded(Creates Metadata for an actively recorded record with the provided client ID. |
static final @NonNull Metadata |
activelyRecordedWithId(@NonNull String id, @NonNull Device device)Creates Metadata to update a record with an existing UUID. |
static final @NonNull Metadata |
autoRecorded(@NonNull Device device)Creates Metadata for an automatically recorded record. |
static final @NonNull Metadata |
autoRecorded(Creates Metadata for an automatically recorded record with the provided client ID. |
static final @NonNull Metadata |
autoRecordedWithId(@NonNull String id, @NonNull Device device)Creates Metadata to update a record with an existing UUID. |
boolean |
|
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 |
getId()Unique identifier of this data, assigned by Health Connect 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 |
hashCode() |
static final @NonNull Metadata |
manualEntry(Device device)Creates Metadata for a manually entered record. |
static final @NonNull Metadata |
manualEntry(Creates Metadata for a manually entered record with the provided client ID. |
static final @NonNull Metadata |
manualEntryWithId(@NonNull String id, Device device)Creates Metadata to update a record with an existing UUID. |
@NonNull String |
toString() |
static final @NonNull Metadata |
unknownRecordingMethod(Device device)Creates Metadata with unknown recording method. |
static final @NonNull Metadata |
unknownRecordingMethod(Creates Metadata with unknown recording method with the provided client ID. |
static final @NonNull Metadata |
unknownRecordingMethodWithId(@NonNull String id, Device device)Creates Metadata to update a record with an existing UUID. |
Extension functions |
|
|---|---|
final @NonNull Metadata |
MetadataTestHelper.populatedWithTestValues(Creates a new |
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
public static final @NonNull Metadata activelyRecorded(@NonNull Device device)
Creates Metadata for an actively recorded record.
RECORDING_METHOD_ACTIVELY_RECORDED is auto populated.
activelyRecorded
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.
activelyRecordedWithId
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.
autoRecorded
public static final @NonNull Metadata autoRecorded(@NonNull Device device)
Creates Metadata for an automatically recorded record.
RECORDING_METHOD_AUTOMATICALLY_RECORDED is auto populated.
autoRecorded
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.
autoRecordedWithId
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.
getClientRecordId
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.
| See also | |
|---|---|
clientRecordVersion |
getClientRecordVersion
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
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
public final Device getDevice()
Optional client supplied device information associated with the data.
getId
public final @NonNull String getId()
Unique identifier of this data, assigned by Health Connect at insertion time. When Record is created before insertion, this takes a sentinel value, any assigned value will be ignored.
getLastModifiedTime
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
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.
manualEntry
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.
manualEntry
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.
manualEntryWithId
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.
unknownRecordingMethod
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.
unknownRecordingMethod
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.
unknownRecordingMethodWithId
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.
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 specified properties for testing.
This method facilitates the creation of Metadata instances with controlled values, particularly useful for unit testing scenarios where specific metadata properties need to be set. It constructs a new Metadata object based on the current instance, allowing the modification of the id, dataOrigin, and lastModifiedTime fields.
| Parameters | |
|---|---|
@NonNull String id |
The ID to assign to the new |
@NonNull DataOrigin dataOrigin |
The |
@NonNull Instant lastModifiedTime |
The |