Class HealthDeleteRequest
Describes what to delete from HealthStore, either by identifier or
by type and time range.
You can only delete your own data
Both platforms restrict deletion to samples your app wrote. A request covering another app's data silently deletes nothing rather than failing, which is a deliberate platform choice: an app must not be able to discover what other apps recorded by watching which deletes succeed.
-
Method Summary
Modifier and TypeMethodDescriptionaddType(HealthDataType type) Adds another type to a range-based request.static HealthDeleteRequestbyId(HealthDataType type, String sampleId) Deletes one sample oftypeby its platform identifier.static HealthDeleteRequestbyIds(HealthDataType type, List<String> sampleIds) Deletes specific samples oftypeby their platform identifiers.static HealthDeleteRequestbyRange(HealthDataType type, HealthTimeRange range) Deletes everything oftypethat this app wrote insiderange.The identifiers to delete, empty for a range-based request.The span to delete within, null for an identifier-based request.getTypes()The types to delete, empty for an identifier-based request.booleanisById()truewhen this request names specific samples rather than a span.voidvalidate()Validates the request.
-
Method Details
-
byIds
Deletes specific samples of
typeby their platform identifiers.The type is required, not redundant: Health Connect deletes by record class plus id and cannot resolve an id on its own, so a request without one could only be honoured by guessing. Asking for it here means the caller states what they are deleting rather than the platform silently deleting nothing.
-
byId
Deletes one sample oftypeby its platform identifier. -
byRange
Deletes everything oftypethat this app wrote insiderange. -
addType
Adds another type to a range-based request. -
getSampleIds
-
getTypes
The types to delete, empty for an identifier-based request. -
getTimeRange
The span to delete within, null for an identifier-based request. -
isById
public boolean isById()truewhen this request names specific samples rather than a span. -
validate
Validates the request.
Throws
HealthException:HealthError.INVALID_ARGUMENTwhen the request names neither identifiers nor a type and range, or ambiguously names both.
- Throws:
HealthException
-