新手上路使用者規劃
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
許多應用程式都有自訂的新手上路流程,例如功能教學,或徵詢使用者同意。如要讓 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 應用程式,而非從您的應用程式內部啟動連線。如果您的應用程式需要任何額外互動,除了授予讀取或寫入資料的權限之外,請提供新手上路活動。
版本支援
如要同時支援 Android 14 以下和 Android 14 以上版本的裝置:
匯出活動的必要條件
如果使用者嘗試將應用程式與 Health Connect 連線,系統就會啟動匯出的活動。此活動必須符合下列條件:
- 顯示任何相關的使用者教學內容,例如說明會寫入或讀取哪些資料。
- 視情況徵詢使用者同意。
- 向 Health Connect 提出權限要求。
- 執行任何其他應用程式專屬邏輯,例如安排週期性 worker。
- 完成後,允許使用者關閉活動。
對於「未」匯出新手上路活動的應用程式,Health Connect 會在使用者嘗試連線應用程式時,改為將他們導向「管理權限」畫面。如果應用程式必須取得權限,整合項目才能正常運作,或許就可以採用上述做法。
請注意,新手上路活動可能會多次啟動,例如使用者之後撤銷授予應用程式的權限,然後又重新連結,就會發生此情況。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[null,null,["上次更新時間: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."]]