目录

DeleteOptions

Class Info

public class DeleteOptions

Request parameter class for deleting data and activity records within a specified period of time from Health Service Kit. An app can delete only the data and activity records added by itself.

When constructing a DeleteOptions object to delete data, you must specify the time range for the data deletion, and specify a DataType or multiple DataCollector objects as needed. You can also choose to delete all data. If none is specified, no data of the app will be deleted.

The sample code is as follows:

  1. Build DeleteOptions to delete the data of a specified DataType (DT_CONTINUOUS_STEPS_DELTA).
    The sample code is as follows:
    Java
    DeleteOptions deleteOptions = new DeleteOptions.Builder()
        .setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS)
        .addDataType(DataType.DT_CONTINUOUS_STEPS_DELTA)
        .build();
    Kotlin
    val deleteOptions = DeleteOptions.Builder()
        .addDataType(DataType.DT_CONTINUOUS_STEPS_DELTA)
        .setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS)
        .build()
  2. Build DeleteOptions to delete the data of multiple specified DataType objects (DT_CONTINUOUS_STEPS_DELTA and DT_INSTANTANEOUS_HEIGHT).
    The sample code is as follows:
    Java
    DeleteOptions deleteOptions = new DeleteOptions.Builder()
        .setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS)
        .addDataType(DataType.DT_CONTINUOUS_STEPS_DELTA)
        .addDataType(DataType.DT_INSTANTANEOUS_HEIGHT)
        .build();
    Kotlin
    val deleteOptions = DeleteOptions.Builder()
        .setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS)
        .addDataType(DataType.DT_CONTINUOUS_STEPS_DELTA)
        .addDataType(DataType.DT_INSTANTANEOUS_HEIGHT)
        .build()
  3. Build DeleteOptions to delete the data of a DataType (DT_CONTINUOUS_STEPS_DELTA) and from multiple DataCollectors (multiple devices).
    The sample code is as follows:
    Java
    DeleteOptions deleteOptions = new DeleteOptions.Builder()
        .setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS)
        .addDataType(DataType.DT_CONTINUOUS_STEPS_DELTA)
        .addDataCollector(dataCollector1)
        .addDataCollector(dataCollector2)
        .build();
    Kotlin
    val deleteOptions = DeleteOptions.Builder()
        .setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS)
        .addDataType(DataType.DT_CONTINUOUS_STEPS_DELTA)
        .addDataCollector(dataCollector1)
        .addDataCollector(dataCollector2)
        .build()
  4. Build DeleteOptions to delete all data of the app.
    The sample code is as follows:
    Java
    DeleteOptions deleteOptions = new DeleteOptions.Builder()
        .setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS)
        .deleteAllData()
        .build();
    Kotlin
    val deleteOptions = DeleteOptions.Builder()
        .setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS)
        .deleteAllData()
        .build()

When constructing a DeleteOptions object to delete activity records, you must specify the time range for the activity records to be deleted. You can also specify one or more ActivityRecord objects as needed, or choose to delete all ActivityRecords. If not specified, no activity record will be deleted.

The sample code for constructing a DeleteOptions object to delete activity records is as follows:

  1. Specify DeleteOptions to delete two activity records (activityRecordRunning and activityRecordSwimming).
    The sample code is as follows:
    Java
    DeleteOptions deleteOptions = new DeleteOptions.Builder()
        .setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS)
        .addActivityRecord(activityRecordRunning)
        .addActivityRecord(activityRecordSwimming)
        .build();
    Kotlin
    val deleteOptions = DeleteOptions.Builder()
        .setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS)
        .addActivityRecord(activityRecordRunning)
        .addActivityRecord(activityRecordSwimming)
        .build()
  2. Build DeleteOptions to delete all activity records for the app.
    The sample code is as follows:
    Java
    DeleteOptions deleteOptions = new DeleteOptions.Builder()
        .setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS)
        .deleteAllActivityRecords()
        .build();
    Kotlin
    val deleteOptions = DeleteOptions.Builder()
        .setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS)
        .deleteAllActivityRecords()
        .build()

Nested Class Summary

Qualifier and Type

Class Name and Description

public static class

DeleteOptions.Builder

Builder for DeleteOptions.

Public Method Summary

Qualifier and Type

Method Name and Description

boolean

deleteAllActivityRecords()

Indicates whether to delete all activity records.

boolean

deleteAllData()

Indicates whether to delete all data.

List<ActivityRecord>

getActivityRecords()

Obtains the activity records to be deleted.

List<DataCollector>

getDataCollectors()

Obtains the list of data collectors whose data is to be deleted.

List<DataType>

getDataTypes()

Obtains the types of data to be deleted.

long

getEndTime(TimeUnit timeUnit)

Obtains the end time of the data range to be deleted.

long

getStartTime(TimeUnit timeUnit)

Obtains the start time of the data range to be deleted.

Public Methods

[h2]deleteAllActivityRecords()

Method

public boolean deleteAllActivityRecords()

Indicates whether to delete all activity records.

Returns

Type

Description

boolean

Whether all activity records are deleted:

  • true: yes
  • false: no

[h2]deleteAllData()

Method

public boolean deleteAllData()

Indicates whether to delete all data.

Returns

Type

Description

boolean

Whether all data is deleted:

  • true: yes
  • false: no

[h2]getActivityRecords()

Method

public List<ActivityRecord> getActivityRecords()

Obtains the activity records to be deleted.

Returns

Type

Description

List<ActivityRecord>

List of activity records to be deleted. If none has been specified, the list is empty.

[h2]getDataCollectors()

Method

public List<DataCollector> getDataCollectors()

Obtains the list of data collectors whose data is to be deleted.

Returns

Type

Description

List<DataCollector>

List of data collectors whose data is to be deleted. If none has been specified, the list is empty.

[h2]getDataTypes()

Method

public List<DataType> getDataTypes()

Obtains the types of data to be deleted.

Returns

Type

Description

List<DataType>

List of data types whose data is to be deleted. If none has been specified, the list is empty.

[h2]getEndTime(TimeUnit timeUnit)

Method

public long getEndTime(TimeUnit timeUnit)

Obtains the end time of the data range to be deleted.

Parameters

Name

Description

timeUnit

Time unit.

Returns

Type

Description

long

Obtains the end time in a specified time unit.

[h2]getStartTime(TimeUnit timeUnit)

Method

public long getStartTime(TimeUnit timeUnit)

Obtains the start time of the data range to be deleted.

Parameters

Name

Description

timeUnit

Time unit.

Returns

Type

Description

long

Start time in a specified time unit.