为新用户制定计划
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
许多应用都有自定义的新用户引导流程,例如功能教程或征求用户同意。如需让 Health Connect 启动初始配置流程,请在清单中添加以下代码:
<!-- 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 应用(而非从您的应用内)发起与您的应用的关联。如果您的应用除了获得读取或写入数据的权限之外,还需要任何其他互动,请提供新用户引导 activity。
版本支持
如需同时支持 Android 14 之前的设备和 Android 14 及更高版本的设备,请执行以下操作:
导出的 activity 要求
当用户尝试将您的应用连接到 Health Connect 时,系统会启动导出的 activity。此 activity 必须执行以下操作:
- 显示任何相关的用户教程,例如说明系统会写入或读取哪些数据。
- 视需要征求用户同意。
- 向 Health Connect 发出权限请求。
- 执行任何其他特定于应用的逻辑,例如调度一项定期 worker。
- 完成后,允许用户关闭此 activity。
对于不导出新用户引导 activity 的应用,Health Connect 会改为一旦用户尝试连接该应用,就将用户定向到管理权限界面。对于权限授予是确保集成正常运行的唯一前提条件的应用,这种做法可能是可以接受的。
请注意,新用户引导 activity 可能会多次启动,例如,如果用户之后撤消了应用的权限,然后重新连接了该应用。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],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."]]