$30 off During Our Annual Pro Sale. View Details »

2022年ヘルスケアアプリのつくり方 / 2022 A Healthcare App Odyssey

gyamoto
October 06, 2022

2022年ヘルスケアアプリのつくり方 / 2022 A Healthcare App Odyssey

DroidKaigi2022 Day.2 Room:Cards 14:45-15:10
https://droidkaigi.jp/2022/timetable/365018

gyamoto

October 06, 2022
Tweet

More Decks by gyamoto

Other Decks in Technology

Transcript

  1. 2022೥ ϔϧεέΞΞϓϦͷ ͭ͘Γํ Kohei Yamamoto 1

  2. ࣗݾ঺հ Kohei Yamamoto farundorl gyamoto Android application engineer Mobility Technologies

    (2021.08 - , Main job) Upmind (2022.01 - , Side job) 2 Name : Twitter : GitHub : Job :
  3. Mobility
 Technologies λΫγʔΞϓϦʮ(0ʯΛ͸͡Ίͱ ͨ͠ҠಈʹؔΘΔαʔϏεΛ։ൃ Ұॹʹಇ͘ϝϯόʔืूதʂʂ %SPJE,BJHJεϙϯαʔϒʔεలࣔ΍ "OESPJEษڧձ΍͍ͬͯ·͢ 3

  4. Upmind ࣗ཯ਆܦΛܭଌͯ͠৺ͱମΛ੔͑Δ ϚΠϯυϑϧωεΞϓϦ 
 ։ൃͰಘΒΕͨ஌ݟΛ΋ͱʹɺ 
 ϔϧεέΞΞϓϦͷͭ͘ΓํΛ঺հ 4

  5. ͜ͷηογϣϯͰ࿩͢͜ͱ ϔϧεέΞΞϓϦ͕ѻ͏σʔλͱϓϥοτϑΥʔϜʹ͍ͭͯ ϓϥοτϑΥʔϜಋೖΛߟ͑Δ HealthConnectͷಋೖ ·ͱΊ 01 02 03 04 5

    2022೥ ϔϧεέΞΞϓϦͷͭ͘Γํ
  6. ͜ͷηογϣϯͰ࿩͢͜ͱ 6 2022೥ ϔϧεέΞΞϓϦͷͭ͘Γํ 01 02 03 04 ϔϧεέΞΞϓϦ͕ѻ͏σʔλͱϓϥοτϑΥʔϜʹ͍ͭͯ ϓϥοτϑΥʔϜಋೖΛߟ͑Δ

    HealthConnectͷಋೖ ·ͱΊ
  7. ϔϧεέΞΞϓϦ࢖ͬͯΔʁ GooglePlayͷʮ݈߁ˍϑΟοτωεʯΧςΰϦʹ৺਎ͷ݈߁؅ཧΛ໨తͱͨ͠
 ༷ʑͳϔϧεέΞΞϓϦ͕ެ։͞Ε͍ͯΔɻ ϔϧεέΞΞϓϦͷྫ • ೔ʑͷ׆ಈʢา਺ɺ৺ഥɺਭ຾ɺମॏʣΛৼΓฦΔ • ӡಈʢےτϨɺϥϯχϯάʣ΍৯ੜ׆ͷه࿥ • ϚΠϯυϑϧωεͷৄ͍͠ํ๏Λઆ໌

    7
  8. ϔϧεέΞΞϓϦ͕ѻ͏σʔλ ϔϧεέΞΞϓϦͰ͸Ϣʔβͷ݈߁ʹؔ͢Δ༷ʑͳσʔλ͕ѻΘΕ͍ͯΔɻ ϔϧεέΞΞϓϦ͕ѻ͏σʔλͷྫ • Ϣʔβࢦඪ → ਎௕ɺମॏɺ৺ഥ਺ɺମԹɺମࢷ๱཰ɺݺٵ਺ɺͳͲ • ਭ຾ →

    ਭ຾࣌ؒɺ࣌ؒ͋ͨΓͷਭ຾ͷਂ͞ • ϥϯχϯά → ӡಈ࣌ؒɺ࣌ؒ͋ͨΓͷ଎౓ • ΤΫααΠζ → ࣮ࢪͨ͠ӡಈɺӡಈ࣌ؒɺ࣌ؒ͋ͨΓͷ৺ഥ਺ 8
  9. ϔϧεέΞΞϓϦͱϓϥοτϑΥʔϜ ϔϧεέΞΞϓϦຖʹѻΘΕ͍ͯΔσʔλΛڞ༗͢Δ࢓૊Έͱͯ͠ɺϔϧεέΞ ϓϥοτϑΥʔϜ͕։ൃɺఏڙ͞Ε͍ͯΔɻ ϓϥοτϑΥʔϜʹ࿈ܞ͢Δ͜ͱͰɺෳ਺ͷΞϓϦ͕ͦΕͧΕ࣋ͭσʔλΛूܭ ͯ͠׆ಈه࿥ͱͯ͠ৼΓฦΔ͜ͱ͕Ͱ͖ɺ׆ಈه࿥Λ΋ͱʹద੾ͳίϯςϯπΛ קΊΔ౳ͷσʔλ׆༻͕Ͱ͖Δɻ 9

  10. ϔϧεέΞΞϓϦͷϓϥοτϑΥʔϜଟ͗͢໰୊ 2022೥ݱࡏɺଟ͘ͷϔϧεέΞΞϓϦͷϓϥοτϑΥʔϜ͕ఏڙ͞Ε͍ͯΔɻ
 ΞϓϦʹΑͬͯ࿈ܞ͍ͯ͠ΔϓϥοτϑΥʔϜ͕ҟͳΔ৔߹͸ɺϢʔβͷσʔλ͕ ϓϥοτϑΥʔϜͷนͰ෼அͯ͠͠·͏ɻ ෼அͯ͠͠·ͬͨྫ • าߦɺ৺ഥ → SamsungHealth •

    ਭ຾࣌ؒ → Fitbit • ମॏ → OMRON connect → Google Fit 10
  11. ৽͍͠ϓϥοτϑΥʔϜ HealthConnect ϓϥοτϑΥʔϜଟ͗͢໰୊Λղܾ͢ΔͨΊʹɺGoogle I/O 2022 Ͱൃද͞Εͨ ৽͍͠ϓϥοτϑΥʔϜɻ ͦΕͧΕϓϥοτϑΥʔϜΛ࣋ͭGoogleͱSamsung͕։ൃɻ
 ࠓळʹGoogleFit, Fitbit,

    SamsungHealth͕HealthConnectʹରԠ༧ఆɻ ଞʹ΋MyFitnessPal, LeapFitness, Withingsͱଟ͘ͷϔϧεέΞαʔϏε͕։ൃʹ ڠྗ͍ͯ͠Δɻ 11
  12. HealthConnectͷಛ௃ • AndroidσόΠεʹඥ͍ͮͨσόΠεத৺ͷσʔλ؅ཧ • σʔλछผ୯Ґͷࡉ͔͍ݖݶ੍ޚ • Android 9.0Ҏ͕߱ඞཁ • 2022೥10݄5೔࣌఺ͰΞϧϑΝ൛ʢ1.0.0-alpha06ʣ

    12
  13. GoogleFitͷಛ௃ • GoogleΞΧ΢ϯτʹඥ͍ͮͨαʔόத৺ͷσʔλ؅ཧ • OAuthʹΑΔݖݶ੍ޚ • Android 4.1Ҏ͕߱ඞཁ • Android޲͚API͸2022೥5݄͔Βඇਪ঑ɻ2024೥ʹαϙʔτऴྃ༧ఆ

    13
  14. σʔλ؅ཧ HealthConnect σόΠεத৺ͷσʔλ؅ཧ → σόΠε͔Βফ͑Δͱ෮׆ෆՄ 14 GoogleFit αʔόத৺ͷσʔλ؅ཧ → GoogleΞΧ΢ϯτ͋Ε͹෮׆

    HealthConnectͱGoogleFitͷൺֱ
  15. ݖݶ੍ޚ HealthConnect σʔλछผຖͷΞΫηεݖ ʢಡΈऔΓɺॻ͖ࠐΈʣͷݖݶ੍ޚ → ࣮૷͸ෳࡶ
 → Ϣʔβͱͯ͠خ͍͠ 15 GoogleFit

    ΞϓϦ୯ҐͷΞΫηεݖʢෳ਺σʔλ छผΛ·ͱΊͨʣͷOAuthݖݶ੍ޚ → ࣮૷͸γϯϓϧ
 → ΤϯδχΞͱͯ͠خ͍͠ HealthConnectͱGoogleFitͷൺֱ
  16. OSόʔδϣϯ HealthConnect Android 9.0Ҏ߱ → 9.0Ҏ߱ͷϢʔβ͕େ෦෼Λ઎ΊΔ
 → 8.1ະຬͷϢʔβ΋࣮֬ʹ࢒ͬͯ
 ɹ͍ΔͷͰɺ೰·͍͠… 16

    GoogleFit Android 4.1Ҏ߱ → 10೥લͷOSͰ΋ಈ͘ʂʂ HealthConnectͱGoogleFitͷൺֱ
  17. ҆ఆੑͱকདྷੑ HealthConnect ΞϧϑΝ൛
 طଘϓϥοτϑΥʔϜ͸ରԠ༧ఆ → ·ͩAPIʹഁյతมߋ͸͋Γͦ͏
 → GoogleFitҎ֎ͷϓϥοτϑΥʔϜ
 ɹͱ࿈ܞͰ͖Δʂʂ 17

    GoogleFit 2022೥5݄͔Βඇਪ঑
 2024೥ʹαϙʔτऴྃ༧ఆ → ಈ࡞͸҆ఆ͍ͯ͠Δ
 → ৽͘͠ಋೖ͢Δͷ͸ආ͚͍ͨ HealthConnectͱGoogleFitͷൺֱ
  18. HealthConnectͱGoogleFitͷൺֱ 18 HealthConnect GoogleFit ɹσʔλ؅ཧ ̋ σόΠεத৺ ˕ αʔόத৺ ɹݖݶ੍ޚ

    ˕ σʔλͱΞΫηεݖ୯Ґ ˚ ΞϓϦ୯Ґ ɹOSόʔδϣϯ ˚ Android 9.0~ ̋ Android 4.1~ ɹ҆ఆੑ ˚ ·ͩΞϧϑΝ൛ ̋ ҆ఆ൛ ɹকདྷੑ ˕ طଘϓϥοτϑΥʔϜ͕ରԠ༧ఆ ˚ Android޲͚API͸ඇਪ঑
  19. ͜ͷηογϣϯͰ࿩͢͜ͱ 19 2022೥ ϔϧεέΞΞϓϦͷͭ͘Γํ 01 02 03 04 ϔϧεέΞΞϓϦ͕ѻ͏σʔλͱϓϥοτϑΥʔϜʹ͍ͭͯ ϓϥοτϑΥʔϜಋೖΛߟ͑Δ

    HealthConnectͷಋೖ ·ͱΊ
  20. എܠ ઌߦͯ͠iOS൛͕ެ։͞Ε͍ͯΔ
 ϚΠϯυϑϧωεΞϓϦUpmindͷ Android൛Λ࣮૷͢Δɻ 20 ϓϥοτϑΥʔϜಋೖ Λߟ͑Δ

  21. ػೳ ɾσόΠεͷΧϝϥͰࣗ཯ਆܦΛܭଌ ɾϚΠϯυϑϧωεΛվળ͢ΔͨΊͷ
 ɹίϯςϯπΛఏڙ͢Δ 21 ϓϥοτϑΥʔϜಋೖ Λߟ͑Δ

  22. UpmindͷϓϥοτϑΥʔϜಋೖํ਑ HealthConnectΛಋೖ͢Δ ɾGoogleFit͸Android޲͚API͕ඇਪ঑ͷͨΊɺ৽نΞϓϦ΁ͷಋೖ͸ආ͚͍ͨ ɾAndroidόʔδϣϯ΋΄΅ຬͨ͢͜ͱ͕Ͱ͖ΔʢAndroid 8.0~8.1ͷΈະରԠʣ ϔϧεέΞϓϥοτϑΥʔϜͱͷ࿈ܞ͸iOS࣮૷Λࢀߟʹ͢Δ ɾiOS൛͸AppleͷϔϧεέΞϓϥοτϑΥʔϜ HealthKit ͱ࿈ܞ͍ͯ͠Δ ɾ΄΅ಉ͡σʔλछผ͕HealthConnectʹ༻ҙ͞Ε͍ͯΔ

    22
  23. 23 σόΠεͷΧϝϥͰࣗ཯ਆܦείΞ ʢ৺ഥͷΏΒ͗ɺ৺ഥ਺ʣΛܭଌ → ܭଌͨ͠৺ഥ਺ͷॻ͖ࠐΈ HealthConnectʹ
 ࿈ܞ͢Δσʔλ

  24. 24 վળίϯςϯπఏҊ༻ͷࢦඪΛऔಘ
 → า਺ɺਭ຾ɺফඅΧϩϦʔͷಡΈऔΓ Ϣʔβ͕࣮ࢪͨ͠վળίϯςϯπ
 ʢᛉ૝ɺϤΨɺετϨονʣΛه࿥͢Δ
 → ΞΫςΟϏςΟͷॻ͖ࠐΈ
 HealthConnectʹ
 ࿈ܞ͢Δσʔλ

  25. UpmindͰѻ͏σʔλͷϑϩʔΛߟ͑Δ σʔλͷ׆༻
 
 վળίϯςϯπʢᛉ૝ɺ ϤΨɺετϨονʣ 25 σʔλͷอଘ
 
 ΞϓϦαʔόʹࣗ཯ਆ ܦείΞΛอଘ

    ϓϥοτϑΥʔϜ࿈ܞ
 
 า਺ɺਭ຾ɺফඅΧϩ ϦʔΛऔಘ σʔλͷೖྗ
 
 ࣗ཯ਆܦείΞʢ৺ഥͷ ΏΒ͗ɺ৺ഥ਺ʣΛܭଌ ϓϥοτϑΥʔϜ࿈ܞ
 
 ৺ഥ਺ͷॻ͖ࠐΈ
  26. UpmindͰѻ͏σʔλͷϑϩʔΛߟ͑Δ σʔλͷ׆༻
 
 վળίϯςϯπʢᛉ૝ɺ ϤΨɺετϨονʣ 26 Ϣʔβମݧ
 
 վળίϯςϯπΛࢹ ௌɺମݧ

    ϓϥοτϑΥʔϜ࿈ܞ
 
 վળίϯςϯπͷ࣮ࢪ Λॻ͖ࠐΈ σʔλͷอଘ
 
 ΞϓϦαʔόʹվળίϯ ςϯπͷࢹௌ׬ྃΛอଘ
  27. ͜ͷηογϣϯͰ࿩͢͜ͱ 27 2022೥ ϔϧεέΞΞϓϦͷͭ͘Γํ 01 02 03 04 ϔϧεέΞΞϓϦ͕ѻ͏σʔλͱϓϥοτϑΥʔϜʹ͍ͭͯ ϓϥοτϑΥʔϜಋೖΛߟ͑Δ

    HealthConnectͷಋೖ ·ͱΊ
  28. HealthConnectͷಋೖ AndroidStudio : HealthConnect : UI impl : Async impl

    : Gradle script : 28 Dolphin | 2021.3.1 1.0.0-alpha05 Jetpack Compose 1.2.1 Kotlin Coroutines 1.6.0 Groovy AndroidΞϓϦ͔ΒHealthConnectͷݖݶऔಘͱσʔλͷಡΈॻ͖Λ࣮૷͢Δɻ ಈ࡞؀ڥͱόʔδϣϯ
  29. HealthConnectͷಋೖखॱ I. ϥΠϒϥϦಋೖͱϓϩδΣΫτઃఆ II. σʔλछผΛܾΊΔ III.ར༻Մ൱൑ఆ IV.ݖݶͷऔಘ V. σʔλͷಡΈࠐΈ VI.σʔλͷॻ͖ࠐΈ

    29
  30. I. HealthConnectͷϥΠϒϥϦಋೖͱϓϩδΣΫτઃఆ 1. app/build.gradle ʹHealthConnectϥΠϒϥϦͷґଘؔ܎Λ௥Ճ͢Δ 30 dependencies { implementation 'androidx.health.connect:connect-client:1.0.0-alpha05'

    }
  31. I. HealthConnectͷϥΠϒϥϦಋೖͱϓϩδΣΫτઃఆ 2. AndroidManifest.xml ʹHealthConnectͷݖݶ࢖༻ํ๏Λઆ໌͢ΔActivityΛ௥Ճ ͢Δ 31 <activity android:name=".PermissionsRationaleActivity"> <intent-filter>

    <action android:name="androidx.health.ACTION_SHOW_PERMISSIONS_RATIONALE" /> </intent-filter> <!-- TODO: σʔλछผͱΞΫηεݖΛ health_permission.xml ʹఆٛ͢Δ --> <meta-data android:name="health_permissions" android:resource="@array/health_permissions" />
  32. I. HealthConnectͷϥΠϒϥϦಋೖͱϓϩδΣΫτઃఆ 3. AndroidManifest.xml ʹHealthConnectΞϓϦͱͷ࿈ܞઃఆΛ௥Ճ͢Δ 32 <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.upmind.ui">

    <queries> <!-- HealthConnectΞϓϦ͕Πϯετʔϧ͞Ε͍ͯΔ͔֬ೝ͢Δ --> <package android:name="com.google.android.apps.healthdata" /> </queries>
  33. II. HealthConnectͷσʔλछผΛܾΊΔ 1. iOSͷHealthKitͱಉ༷ͷσʔλछผΛHealthConnectͰݕ౼͢Δ 33 let writeTypes = Set([ HKObjectType.quantityType(forIdentifier:

    HKQuantityTypeIdentifier.heartRate)!, HKObjectType.categoryType(forIdentifier: HKCategoryTypeIdentifier.mindfulSession)! ]) let readTypes = Set([ HKObjectType.quantityType(forIdentifier: HKQuantityTypeIdentifier.stepCount)!, HKObjectType.categoryType(forIdentifier: HKCategoryTypeIdentifier.sleepAnalysis)!, HKObjectType.quantityType(forIdentifier: HKQuantityTypeIdentifier.activeEnergyBurned)! ])
  34. II. HealthConnectͷσʔλछผΛܾΊΔ 2. HealthConnectͷσʔλछผʢRecordΠϯλʔϑΣʔεʣʹఆٛ͞Εͨ
 ৺ഥɺϚΠϯυϑϧωεɺา਺ɺਭ຾ɺΤωϧΪʔফඅྔͷΫϥεΛ୳͢… 34 ActiveCaloriesBurnedRecord, BasalBodyTemperatureRecord, BasalMetabolicRateRecord, BloodGlucoseRecord,

    BloodPressureRecord, BodyFatRecord, BodyTemperatureRecord, BoneMassRecord, CervicalMucusRecord, CyclingPedalingCadenceRecord, DistanceRecord, ElevationGainedRecord, ExerciseEventRecord, ExerciseLapRecord, ExerciseRepetitionsRecord, ExerciseSessionRecord, FloorsClimbedRecord, HeartRateRecord, HeightRecord, HipCircumferenceRecord, HydrationRecord, LeanBodyMassRecord, MenstruationFlowRecord, NutritionRecord, OvulationTestRecord, OxygenSaturationRecord, PowerRecord, RespiratoryRateRecord, RestingHeartRateRecord, SexualActivityRecord, SleepSessionRecord, SleepStageRecord, SpeedRecord, StepsCadenceRecord, StepsRecord, SwimmingStrokesRecord, TotalCaloriesBurnedRecord, Vo2MaxRecord, WaistCircumferenceRecord, WeightRecord, WheelchairPushesRecord
  35. ActiveCaloriesBurnedRecord, BasalBodyTemperatureRecord, BasalMetabolicRateRecord, BloodGlucoseRecord, BloodPressureRecord, BodyFatRecord, BodyTemperatureRecord, BoneMassRecord, CervicalMucusRecord, CyclingPedalingCadenceRecord,

    DistanceRecord, ElevationGainedRecord, ExerciseEventRecord, ExerciseLapRecord, ExerciseRepetitionsRecord, ExerciseSessionRecord, FloorsClimbedRecord, HeartRateRecord, HeightRecord, HipCircumferenceRecord, HydrationRecord, LeanBodyMassRecord, MenstruationFlowRecord, NutritionRecord, OvulationTestRecord, OxygenSaturationRecord, PowerRecord, RespiratoryRateRecord, RestingHeartRateRecord, SexualActivityRecord, SleepSessionRecord, SleepStageRecord, SpeedRecord, StepsCadenceRecord, StepsRecord, SwimmingStrokesRecord, TotalCaloriesBurnedRecord, Vo2MaxRecord, WaistCircumferenceRecord, WeightRecord, WheelchairPushesRecord II. HealthConnectͷσʔλछผΛܾΊΔ 2. HealthConnectͷσʔλछผʢRecordΠϯλʔϑΣʔεʣʹఆٛ͞Εͨ
 ৺ഥɺϚΠϯυϑϧωεɺา਺ɺਭ຾ɺΤωϧΪʔফඅྔͷΫϥεΛ୳͢… 35 ActiveCaloriesBurnedRecord HeartRateRecord SleepSessionRecord SleepStageRecord StepsRecord TotalCaloriesBurnedRecord
  36. II. HealthConnectͷσʔλछผΛܾΊΔ 36 3. UpmindΞϓϦͰѻ͏σʔλΛཧղͯ͠ɺHealthConnectͷσʔλछผΛ୳͢ ɾ৺ഥ → 1෼ؒͷ৺ഥ਺ ɾϚΠϯυϑϧωε →

    Ϣʔβ͕࣮ࢪͨ͠վળίϯςϯπʢᛉ૝ɺϤΨɺετϨονʣ ɾา਺ → 1೔ͷา਺ ɾਭ຾ → 1೔ͷਭ຾࣌ؒʢਭ຾ͷਂ͞͸আ͘ʣ ɾΤωϧΪʔফඅྔ → Ϣʔβ͕1೔׆ಈͯ͠ফඅͨ͠ΤωϧΪʔ
  37. II. HealthConnectͷσʔλछผΛܾΊΔ 37 ɾ৺ഥ → HeartRateRecord ɾϚΠϯυϑϧωε → ExerciseSessionRecord
 ɹɹɹɹɹɹɹɹɹɹ(

    ExerciseType.MEDITATION / YOGA / STRETCHING ) ɾา਺ → StepsRecord ɾਭ຾ → SleepSessionRecord, SleepStageRecord ɾΤωϧΪʔফඅྔ → ActiveCaloriesBurnedRecord, TotalCaloriesBurnedRecord
  38. II. HealthConnectͷσʔλछผΛܾΊΔ 38 Android / HealthConnect iOS / HealthKit ɹ৺ഥ਺

    HeartRateRecord HKQuantityTypeIdentifier.
 heartRate ɹ࣮ࢪͨ͠ 
 ɹվળίϯςϯπ ExerciseSessionRecord HKCategoryTypeIdentifier.
 mindfulSession ɹา਺ StepsRecord HKQuantityTypeIdentifier.
 stepCount ɹਭ຾ SleepSessionRecord HKCategoryTypeIdentifier.
 sleepAnalysis ɹফඅΧϩϦʔ ActiveCaloriesBurnedRecord HKQuantityTypeIdentifier.
 activeEnergyBurned
  39. II. HealthConnectͷσʔλछผΛܾΊΔ 4. ΞϓϦͰ࢖༻͢ΔݖݶΛ res/values/health_permissions.xml ʹఆٛ͢Δ 39 <resources> <!-- ΞϓϦ͔ΒΞΫηε͢ΔHealthConnectͷσʔλछผͱݖݶ

    --> <array name=“health_permissions”> <item>androidx.health.permission.HeartRate.WRITE</item> <item>androidx.health.permission.ActivitySession.WRITE</item> <item>androidx.health.permission.Steps.READ</item> <item>androidx.health.permission.SleepSession.READ</item> <item>androidx.health.permission.ActiveCaloriesBurned.READ</item> </array> </resources>
  40. III. HealthConnectͷར༻Մ൱൑ఆ HealthConnectͷݖݶऔಘલʹɺHealthConnectΞϓϦͷར༻Մೳ൑ఆ͕ඞཁ • Androidόʔδϣϯ͕9.0Ҏ্͔
 → Android 9.0ະຬͷ৔߹͸ϔϧεέΞ࿈ܞͰ͖ͳ͍ͷͰɺ࿈ܞUIΛඇදࣔ • HealthConnectΞϓϦ͕ΠϯετʔϧࡁΈ͔


    → ະΠϯετʔϧͷ৔߹͸ɺGooglePlayͰΞϓϦμ΢ϯϩʔυΛҊ಺͢Δ
 ※ ະΠϯετʔϧͷ৔߹ʹ HealthConnectClient Λੜ੒͢ΔͱΫϥογϡ͢Δ 40
  41. IV. HealthConnectͷݖݶऔಘ 2. ݖݶΛཁٻ͢ΔIntentͷLauncherΛੜ੒͢Δ 41 val permissionContract: ActivityResultContract< Set<HealthPermission>, Set<HealthPermission>

    > = PermissionController.createRequestPermissionResultContract() // JetpackComposeͷ `@Composable` ϝιου಺ val launcher = rememberLauncherForActivityResult(permissionContract) { // TODO: ݖݶͷཁٻ݁Ռ `Set<HealthPermission>` Λݕূ͢Δ }
  42. IV. HealthConnectͷݖݶऔಘ 3. ݖݶΛཁٻ͢Δը໘ભҠΛ͓͜ͳ͏ 42 val PERMISSIONS = setOf( HealthPermission.createWritePermission(HeartRateRecord::class),

    HealthPermission.createWritePermission(ExerciseSessionRecord::class), HealthPermission.createReadPermission(StepsRecord::class), HealthPermission.createReadPermission(SleepSessionRecord::class), HealthPermission.createReadPermission(ActiveCaloriesBurnedRecord::class), ) launcher.launch(PERMISSIONS)
  43. 43 4. HealthConnectͷը໘ભҠ HealthConnectΞϓϦʹભҠͯ͠ɺ ཁٻ͞ΕͨσʔλͷΞΫηεݖݶ ʢಡΈऔΓɺॻ͖ࠐΈʣΛઃఆ͢Δ IV. HealthConnectͷ ݖݶऔಘ

  44. IV. HealthConnectͷݖݶऔಘ 44 5. ཁٻ݁Ռ͔Βݖݶ͕ڐՄ͞Ε͔ͨݕূ͢Δ val client: HealthConnectClient = HealthConnectClient.getOrCreate(context)

    /** @return [PERMISSIONS]ͷݖݶ͢΂͕ͯڐՄ͞Ε͔ͨ */ override suspend fun isAllGranted(): Boolean { return PERMISSION == client.permissionController.getGrantedPermissions(PERMISSION) } /** @return [permissions]ͷݖݶ͕ڐՄ͞Ε͔ͨ */ override suspend fun isGranted(permission: Set<HealthPermission>): Boolean { return permission == client.permissionController.getGrantedPermissions(permission) }
  45. V. HealthConnectͷσʔλಡΈऔΓ 45 ಡΈऔΓϦΫΤετΛੜ੒ͯ͠ɺσʔλΛऔಘ͢Δ /** @return 1೔෼ʢ[date]ʣͷา਺ */ suspend fun

    readSteps(date: LocalDate): List<StepsRecord> { val start = date.atStartOfDay().truncatedTo(ChronoUnit.HOURS) val end = start.plusDays(1L).minusMinutes(1L) val timeRange = TimeRangeFilter.between(start, end) val request = ReadRecordsRequest( recordType = StepsRecord::class, timeRangeFilter = timeRange, ) return client.readRecords(request).records }
  46. VI. HealthConnectͷσʔλॻ͖ࠐΈ 46 ॻ͖ࠐΈϦΫΤετΛੜ੒ͯ͠ɺσʔλΛऔಘ͢Δ /** ࣮ࢪͨ͠ᛉ૝Λॻ͖ࠐΉ */ suspend fun writeMeditation(

    title: String, startTime: LocalDateTime, durationMinutes: Long ) { val zoneOffset = OffsetDateTime.now().offset val session = ExerciseSessionRecord( title = title, exerciseType = ExerciseSessionRecord.ExerciseType.MEDITATION, startTime = startTime.minusMinutes(durationMinutes).toInstant(zoneOffset), startZoneOffset = zoneOffset, endTime = startTime.toInstant(zoneOffset), endZoneOffset = zoneOffset, ) client.insertRecords(listOf(session)) }
  47. 47 HealthConnectʹॻ͖ࠐ͜·Εͨ σʔλ͸ɺHealthConnectΞϓϦͰ छྨຖʹ֬ೝͰ͖Δ VI. HealthConnectͷ σʔλॻ͖ࠐΈ

  48. ͜ͷηογϣϯͰ࿩͢͜ͱ 48 2022೥ ϔϧεέΞΞϓϦͷͭ͘Γํ 01 02 03 04 ϔϧεέΞΞϓϦ͕ѻ͏σʔλͱϓϥοτϑΥʔϜʹ͍ͭͯ ϓϥοτϑΥʔϜಋೖΛߟ͑Δ

    HealthConnectͷಋೖ ·ͱΊ
  49. ·ͱΊ • ϔϧεέΞϓϥοτϑΥʔϜଟ͗͢໰୊Λղܾ͢ΔͨΊͷϓϥοτϑΥʔϜ HealthConnect͕ొ৔ • طଘϓϥοτϑΥʔϜͱൺ΂ΔͱҰ௕Ұ୹͋Δ͕ɺ৽نΞϓϦΛ։ൃ͢Δ؍఺ Ͱ͸Αͦ͞͏ • OSόʔδϣϯɺHealthConnectΞϓϦ͕ΠϯετʔϧࡁΈ͔ɺσʔλछผຖͷ ΞΫηεݖͷঢ়ଶΛߟ͑Δඞཁ͕͋Δ

    49