// Add an activity record to the Health platform
        public async void AddActivityRecord()
        {
            Logger(Split + "Add ActivityRecord");

            // Build the time range of the request object: start time and end time
            Calendar Cal = Calendar.Instance;
            Date     Now = new Date();

            Cal.Time = Now;
            long EndTime = Cal.TimeInMillis;

            Cal.Add(CalendarField.HourOfDay, -1);
            long StartTime = Cal.TimeInMillis;

            // Build the data collector object.
            DataCollector dataCollector =
                new DataCollector.Builder().SetDataType(DataType.DtContinuousStepsDelta)
                .SetDataGenerateType(DataCollector.DataTypeRaw)
                .SetPackageName(this)
                .SetDataCollectorName("DataCollector1")
                .Build();

            // Build the activity statistics and activity record request objects.
            ActivitySummary activitySummary = GetActivitySummary();

            // Create a data collector for total step count statistics.
            // ActivitySummary is used to bear the statistical data.
            DataCollector dataCollector2 =
                new DataCollector.Builder().SetDataType(DataType.DtContinuousStepsTotal)
                .SetDataGenerateType(DataCollector.DataTypeRaw)
                .SetPackageName(this)
                .SetDataCollectorName("DataCollector2")
                .Build();
            SamplePoint samplePoint = new SamplePoint.Builder(dataCollector2).Build();

            samplePoint.GetFieldValue(Field.FieldSteps).SetIntValue(1024);
            activitySummary.DataSummary = new[] { samplePoint };

            // Build the activity record request object
            ActivityRecord activityRecord = new ActivityRecord.Builder().SetName("AddActivityRecordTest")
                                            .SetDesc("Add ActivityRecord")
                                            .SetId("MyAddActivityRecordId")
                                            .SetActivityTypeId(HiHealthActivities.Running)
                                            .SetStartTime(StartTime, TimeUnit.Milliseconds)
                                            .SetEndTime(EndTime, TimeUnit.Milliseconds)
                                            .SetActivitySummary(activitySummary)
                                            .SetTimeZone("+0800")
                                            .Build();

            // Build the sampling sampleSet based on the dataCollector
            SampleSet sampleSet = SampleSet.Create(dataCollector);

            // Build the (DtContinuousStepsDelta) sampling data object and add it to the sampling dataSet
            SamplePoint samplePointDetail =
                sampleSet.CreateSamplePoint().SetTimeInterval(StartTime, EndTime, TimeUnit.Milliseconds);

            samplePointDetail.GetFieldValue(Field.FieldStepsDelta).SetIntValue(1024);
            sampleSet.AddSample(samplePointDetail);

            // Build the activity record addition request object
            ActivityRecordInsertOptions insertRequest =
                new ActivityRecordInsertOptions.Builder().SetActivityRecord(activityRecord).AddSampleSet(sampleSet).Build();

            CheckConnect();

            // Call the related method in the ActivityRecordsController to add activity records
            var AddTask = MyActivityRecordsController.AddActivityRecordAsync(insertRequest);

            try
            {
                await AddTask;

                if (AddTask.IsCompleted)
                {
                    if (AddTask.Exception == null)
                    {
                        Logger("Add ActivityRecord was successful!");
                    }
                    else
                    {
                        PrintFailureMessage(AddTask.Exception, "AddActivityRecord");
                    }
                }
            }
            catch (System.Exception ex)
            {
                PrintFailureMessage(ex, "AddActivityRecord");
            }
        }
        // Start an activity record
        public async void BeginActivityRecord()
        {
            Logger(Split + "Begin ActivityRecord");
            long StartTime = Calendar.Instance.TimeInMillis;

            ActivitySummary activitySummary = new ActivitySummary();

            // Create a data collector for statics data
            // The numbers are generated randomly
            DataCollector dataCollector = new DataCollector.Builder().SetDataType(DataType.DtStatisticsSleep)
                                          .SetDataGenerateType(DataCollector.DataTypeRaw)
                                          .SetPackageName(this)
                                          .SetDataCollectorName("DataCollector1")
                                          .Build();
            SamplePoint samplePoint = new SamplePoint.Builder(dataCollector).Build();

            samplePoint.GetFieldValue(Field.AllSleepTime).SetIntValue(352);
            samplePoint.GetFieldValue(Field.GoBedTime).SetLongValue(1599580041000L);
            samplePoint.GetFieldValue(Field.SleepEfficiency).SetIntValue(4);
            samplePoint.GetFieldValue(Field.DreamTime).SetIntValue(58);
            samplePoint.GetFieldValue(Field.WakeUpTime).SetLongValue(1599608520000L);
            samplePoint.GetFieldValue(Field.DeepSleepTime).SetIntValue(82);
            samplePoint.GetFieldValue(Field.DeepSleepPart).SetIntValue(64);
            samplePoint.GetFieldValue(Field.AwakeTime).SetIntValue(3);
            samplePoint.GetFieldValue(Field.SleepScore).SetIntValue(73);
            samplePoint.GetFieldValue(Field.LightSleepTime).SetIntValue(212);
            samplePoint.GetFieldValue(Field.SleepLatency).SetIntValue(7487000);
            samplePoint.GetFieldValue(Field.WakeUpCnt).SetIntValue(2);
            samplePoint.GetFieldValue(Field.FallAsleepTime).SetLongValue(1599587220000L);

            activitySummary.DataSummary = new[] { samplePoint };

            // Build an ActivityRecord object
            ActivityRecord activityRecord = new ActivityRecord.Builder().SetId("MyBeginActivityRecordId")
                                            .SetName("BeginActivityRecord")
                                            .SetDesc("Begin ActivityRecord")
                                            .SetActivityTypeId(HiHealthActivities.Sleep)
                                            .SetStartTime(StartTime, TimeUnit.Milliseconds)
                                            .SetActivitySummary(activitySummary)
                                            .SetTimeZone("+0800")
                                            .Build();

            CheckConnect();

            var BeginTask = MyActivityRecordsController.BeginActivityRecordAsync(activityRecord);

            try
            {
                await BeginTask;

                if (BeginTask.IsCompleted)
                {
                    if (BeginTask.Exception == null)
                    {
                        Logger("BeginActivityRecord  success");
                    }
                    else
                    {
                        PrintFailureMessage(BeginTask.Exception, "BeginActivityRecord");
                    }
                }
            }
            catch (System.Exception ex)
            {
                PrintFailureMessage(ex, "BeginActivityRecord");
            }
        }