CLASS info |
|---|
public class SettingController |
Provides the setting-related functions. |
Constructor name |
|---|
SettingController() Constructor for SettingController. |
Return | Method |
|---|---|
Task<Void> | disableHiHealth() Disables the HUAWEI Health Kit function. |
Task<DataType> | addDataType(DataTypeAddOptions options) Creates and adds a customized data type. |
Task<DataType> | readDataType(String dataTypeName) Reads the corresponding customized data type based on the data type name. |
Method |
|---|
public Task<Void> disableHiHealth() |
Disables the Health Kit function, cancels user authorization, and cancels all data records. (The task takes effect in 24 hours.) |
The sample code is as follows:
public void disableHiHealth(View view) {
// Cancel all records.
// Display the returned result on the phone screen.
HuaweiHiHealth.getSettingController(context, mSignInHuaweiId)
.disableHiHealth()
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
printFailureMessage(e, "readTodaySummationFromDevice");
}
})
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(Task<Void> task) {
String res = task.isSuccessful() ? "success" : "failed";
logger("disableHiHealth is " + res);
}
});
} Method |
|---|
public Task<DataType> addDataType(DataTypeAddOptions options) |
Creates and adds a customized data type. The name of the created data type must be prefixed with the package name of the app. Otherwise, the creation fails. |
Parameters
Parameter name | Parameter desc |
|---|---|
options | Request options for creating the data type. |
The sample code is as follows:
public void addNewDataType(View view) {
// Obtain the name of the new data type from the text box.
// The new name must start with the package name and end with a customized name.
String dataTypeName = dataTypeNameView.getText().toString();
// Create a DataTypeAddOptions. The options to be added must be specified.
// You can add multiple options.
DataTypeAddOptions dataTypeAddOptions =
new DataTypeAddOptions.Builder().setName(dataTypeName).addField(selectedField).build();
// Add a new data type.
// Display the returned result on the phone screen.
HuaweiHiHealth.getSettingController(context, mSignInHuaweiId)
.addDataType(dataTypeAddOptions)
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
printFailureMessage(e, "addNewDataType");
}
})
.addOnCompleteListener(new OnCompleteListener<DataType>() {
@Override
public void onComplete(Task<DataType> task) {
String res = task.isSuccessful() ? "success" : "failed";
logger("add dataType of " + selectedFieldStr + " is " + res);
if (task.getException() != null) {
logger("getException is " + task.getException().toString());
}
}
});
} Method |
|---|
public Task<DataType> readDataType(String dataTypeName) |
Reads the data type based on the data type name. This method is used to read the customized data types of the app. |
Parameters
Parameter name | Parameter desc |
|---|---|
dataTypeName | Data type name. |
The sample code is as follows:
public void readDataType(View view) {
// Obtain the name of the data type from the text box.
String dataTypeName = dataTypeNameView.getText().toString();
// Obtain the data type of the specified name.
// Display the returned result on the phone screen.
HuaweiHiHealth.getSettingController(context, mSignInHuaweiId)
.readDataType(dataTypeName)
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
printFailureMessage(e, "readDataType");
}
})
.addOnCompleteListener(new OnCompleteListener<DataType>() {
@Override
public void onComplete(Task<DataType> task) {
logger("DataType : " + task.getResult());
}
});
}