HiHealth Core is an open platform for the fitness and health field under HMS Core. The third-party app is able to develop their specific apps using the fitness and health data provided by the HiHealth Core platform. The HMS Core is embedded in the mobile phone. The HiHealth Core subsystem will be dynamically loaded by the HMS Core when necessary. The Hmssdk-hwid is applied to process users' login and authorization scopes. The Healthsdk is the JAR package for third-party apps to connect with the HiHealth Core platform.
This codelab provides a basic third-party app development example. The developer only needs to complete the corresponding code fragment to realize the function development of real-time step counting. This function displays the real-time step count curve, step frequency, total number of steps, and calories burnt on the UI.
D:\codelab\happysport
.app\src\main\java\com\huawei\codelabs\hihealth\happysport\utils\HiHealthSetup.java
.HuaweiIdSignInOptions signInOptions = New HuaweiIdSignInOptions.Builder(HuaweiIdSignInOptions.DEFAULT_SIGN_IN).build();
mHuaweiSignInClient = HuaweiIdSignIn.getClient(activity.getApplicationContext(), signInOptions);
mAccount = HuaweiIdSignIn.getLastSignedInAccount(activity.getApplicationContext());
if (mAccount == null) {
Intent signInIntent = mHuaweiSignInClient.getSignInIntent();
activity.startActivityForResult(signInIntent, REQUEST_CODE_LOGIN);
}
app\src\main\java\com\huawei\codelabs\hihealth\happysport\utils\HiHealthSetup.java
.String[] maxScopes = Scopes.getMaxScopes();
Scope[] allRequiredScopes = new Scope[maxScopes.length];
for (int i = 0; i < allRequiredScopes.length; i++) {
allRequiredScopes[i] = new Scope(maxScopes[i]);
}
HuaweiIdSignIn.requestPermissions(mActivity, REQUEST_CODE_PERMISSION, mAccount, allRequiredScopes);
app\src\main\java\com\huawei\codelabs\hihealth\happysport\viewmodels\HiHealthBaseAdapter\HiHealthBaseAdapter.java
mSensorsClient = HuaweiHiHealth.getSensorsClient(mContext, new FitnessOptions.Builder().build());
app\src\main\java\com\huawei\codelabs\hihealth\happysport\viewmodels\HiHealthBaseAdapter\HiHealthBaseAdapter.java
.DataSource dataSource = new DataSource.Builder()
.setDataType(DataType.TYPE_STEP_COUNT_CUMULATIVE)
.setDevice(new Device("hw", "hw", "hw", 0))
.build();
mSensorsClient.add(new SensorRequest.Builder()
.setDataType(DataType.TYPE_STEP_COUNT_CUMULATIVE)
.build(), mListener);
app\src\main\java\com\huawei\codelabs\hihealth\happysport\viewmodels\HiHealthBaseAdapter\HiHealthBaseAdapter.java
.//private OnDataPointListener mListener = null;
private OnDataPointListener mListener = new OnDataPointListener() {
@Override
public void onDataPoint(DataPoint dataPoint) {
Log.d(TAG, "on data point received");
processDataPoint(this, dataPoint);
}
}
mSensorsClient.remove(mListener);
The following figure shows the implementation.
Well done. You have successfully completed this codelab and learned: