วางแผนสำหรับผู้ใช้การเริ่มต้นใช้งาน
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
แอปหลายแอปมีขั้นตอนการเริ่มต้นใช้งานที่กำหนดเอง เช่น การให้ความรู้เกี่ยวกับฟีเจอร์หรือขอความยินยอมจากผู้ใช้ หากต้องการให้ Health Connect เปิดใช้งานขั้นตอนการเริ่มต้นใช้งาน ให้เพิ่มข้อมูลต่อไปนี้ลงในไฟล์ Manifest
<!-- Required to support pre-Android 14 devices with APK Health Connect -->
<activity
android:name=".OnboardingActivity"
android:exported="true"
android:permission="com.google.android.apps.healthdata.permission.START_ONBOARDING">
<intent-filter>
<action android:name="androidx.health.ACTION_SHOW_ONBOARDING"/>
</intent-filter>
</activity>
<!-- Required to support Android 14+ devices with platform Health Connect -->
<activity-alias
android:name="UAndAboveOnboardingActivity"
android:exported="true"
android:targetActivity=".OnboardingActivity"
android:permission="android.permission.health.START_ONBOARDING">
<intent-filter>
<action android:name="android.health.connect.action.SHOW_ONBOARDING" />
</intent-filter>
</activity-alias>
ผู้ใช้อาจเริ่มการเชื่อมต่อกับแอปของคุณจากแอป Health Connect โดยตรงแทนที่จะมาจากภายในแอปของคุณ หากแอปของคุณต้องมีการโต้ตอบเพิ่มเติมนอกเหนือจากการให้สิทธิ์อ่านหรือเขียนข้อมูล ให้ระบุกิจกรรมเริ่มต้นใช้งาน
การรองรับเวอร์ชัน
หากต้องการรองรับทั้งอุปกรณ์ก่อน Android 14 และ Android 14 ขึ้นไป ให้ทำดังนี้
แนวทางที่แนะนำ: สร้างกิจกรรมการเริ่มต้นใช้งานรายการเดียวที่จัดการทั้ง 2 สถานการณ์ ใช้อีเมลแทนกิจกรรมดังที่แสดงในตัวอย่างเพื่อตรวจสอบความเข้ากันได้ใน Android เวอร์ชันต่างๆ
แนวทางอื่น: ส่งออกกิจกรรม 2 รายการแยกกัน โดยส่งออก 1 รายการสำหรับ Android แต่ละเวอร์ชัน แนวทางนี้อาจทําให้การดูแลรักษามีความซับซ้อนมากขึ้น
ข้อกำหนดของกิจกรรมที่ส่งออก
เมื่อผู้ใช้พยายามเชื่อมต่อแอปกับ Health Connect ระบบจะเปิดกิจกรรมที่ส่งออก กิจกรรมนี้ต้องทําดังนี้
- แสดงการแจ้งข้อมูลผู้ใช้ที่เกี่ยวข้อง เช่น อธิบายว่ามีการเขียนหรืออ่านข้อมูลใด
- ขอให้ผู้ใช้ให้ความยินยอม หากจำเป็น
- ส่งคำขอสิทธิ์ไปยัง Health Connect
- ดำเนินการตามตรรกะอื่นๆ เฉพาะแอปพลิเคชัน เช่น การตั้งเวลาการทํางานเป็นระยะ
- เมื่อดำเนินการเสร็จแล้ว ให้อนุญาตให้ผู้ใช้ปิดกิจกรรม
สําหรับแอปที่ไม่ได้ส่งออกกิจกรรมการเริ่มต้นใช้งาน Health Connect จะนําผู้ใช้ไปยังหน้าจอจัดการสิทธิ์แทนเมื่อผู้ใช้พยายามเชื่อมต่อแอป ซึ่งอาจยอมรับได้สําหรับแอปที่การให้สิทธิ์เป็นข้อกําหนดเบื้องต้นเพียงอย่างเดียวสําหรับการผสานรวมให้ทํางานได้
โปรดทราบว่ากิจกรรมการเริ่มต้นใช้งานอาจเปิดขึ้นมากกว่า 1 ครั้ง เช่น หากผู้ใช้เพิกถอนสิทธิ์เข้าถึงแอปในภายหลังแล้วเชื่อมต่ออีกครั้ง
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-27 UTC
[null,null,["อัปเดตล่าสุด 2025-07-27 UTC"],[],[],null,["# Plan for onboarding users\n\nMany apps have a custom onboarding flow such as feature education or asking user\nconsent. To enable Health Connect to launch your onboarding flow, add the\nfollowing to your manifest: \n\n \u003c!-- Required to support pre-Android 14 devices with APK Health Connect --\u003e\n \u003cactivity\n android:name=\".OnboardingActivity\"\n android:exported=\"true\"\n android:permission=\"com.google.android.apps.healthdata.permission.START_ONBOARDING\"\u003e\n \u003cintent-filter\u003e\n \u003caction android:name=\"androidx.health.ACTION_SHOW_ONBOARDING\"/\u003e\n \u003c/intent-filter\u003e\n \u003c/activity\u003e\n \u003c!-- Required to support Android 14+ devices with platform Health Connect --\u003e\n \u003cactivity-alias\n android:name=\"UAndAboveOnboardingActivity\"\n android:exported=\"true\"\n android:targetActivity=\".OnboardingActivity\"\n android:permission=\"android.permission.health.START_ONBOARDING\"\u003e\n \u003cintent-filter\u003e\n \u003caction android:name=\"android.health.connect.action.SHOW_ONBOARDING\" /\u003e\n \u003c/intent-filter\u003e\n \u003c/activity-alias\u003e\n\nUsers may initiate the connection to your app directly from the Health\nConnect app, rather than from within your app. If your app requires any\nadditional interaction beyond being granted permission to read or write data,\nprovide an onboarding activity.\n\nVersion support\n---------------\n\nTo support both pre-Android 14 and Android 14+ devices:\n\n- **Recommended approach:** Create a single onboarding activity that handles\n both scenarios. Use an activity alias, as shown in the example,to verify\n compatibility across Android versions.\n\n- **Alternative approach:** Export two separate activities,\n one for each Android version. This approach may lead to increased maintenance\n complexity.\n\nExported activity requirements\n------------------------------\n\nWhen a user attempts to connect your app to Health Connect, the exported\nactivity is launched. This activity must do the following:\n\n- Display any relevant user education such as explaining what data is written or read.\n- Ask the user to grant consent if required.\n- Make a permissions request to Health Connect.\n- Carry out any other application specific logic such as scheduling a periodic worker.\n- Once complete, allow the user to dismiss the activity.\n\nFor apps that *don't* export an onboarding activity, Health Connect instead\nbrings the user to the **Manage permissions** screen once the user attempts to\nconnect the app. This may be acceptable for apps where permissions being\ngranted is the only prerequisite for the integration to function.\n\nNote that the onboarding activity may be launched more than once, for example if\nthe user later revokes permissions to your app and then reconnects it."]]