health connect app and samsung health app installed samsung galaxy watch synced to the mobile device google account sample code here is a sample code for you to start coding in this code lab download it and start your learning experience! research app sample code 4 09 mb create a firebase project follow the instructions at firebase google com/docs/android/setup to add a firebase project to the firebase account you created during the backend system installation set applicationid as healthstack sample and download the resulting google-services json file from firebase to learn more, see installing the app sdk - create a firebase project create a new study sign in to the web portal page you deployed on the study collection page, click the create new study button noteonly the account who has team admin role can create a new study see the role-based access control for more details about the differing levels of access permission granted to different roles set your study name and logo then click the continue button to create your study select the principal investigator role and click the confirm button the overview page appears like below to connect your app to the backend system of your web portal, you need to know the id of your study you can get the study id by opening chrome's developer tools right-click on the web portal page and select inspect then, open the network panel click study settings from the left navigation bar you can see activities recorded on the network tab the value after projectid= is the id of the study, which you need to set up in the research app connect the research app to the backend system in android studio, click open to open the project files of the research app locate the downloaded android project codelab-before from the directory and click ok copy and paste the downloaded google-services json from firebase to samples > researchsample module go to samples > researchsample > res > values, and in the strings xml file, set the following values to connect the app to the backend system research_platform_endpoint - backend system’s endpoint, including the port number research_project_id - id of the study created <!-- backend integration --> <string name="research_platform_endpoint">http //you must set backend url</string> <string name="research_project_id">study_id</string> customize the introduction page and eligibility survey the sample research app already includes introduction page and eligibility survey, which you can customize to align with the objective of your study to modify the introduction page and eligibility survey questions, go to samples > researchsample > java > healthstack sample and open the onboardingmodule kt file introduction page go to the intromodel constructor within the intro function, and create two introsections as below overview - "a study on walking over an hour daily versus non-walkers " description - "we want to conduct a study to compare the daily life patterns of people who walk more than an hour each day and those who don't " sections = listof introsection "overview", "a study on walking over an hour daily versus non-walkers ", , introsection "description", "we want to conduct a study to compare the daily life patterns of people " + "who walk more than an hour each day and those who don’t " the introduction page would look like as below eligibility survey part of the onboarding process is asking the participants questions through an eligibility survey to determine their suitability for your study the eligibility survey consists of three steps eligibilityintrostep - displays an introduction about the survey eligibilitycheckerstep - displays the eligibility questions eligibilityresultstep - displays the result of the survey based on the answers the eligibilitycheckerstep receives the eligibilityquestions the questions can be a choicequestionmodel, datatimequestionmodel, or multichoicequestionmodel, depending on the type of survey question model you set modify the eligibility question pages as below eligibility question 1 type choicequestionmodel id average_walking_time query how many minutes on average do you spend walking each day? explanation unit minute candidates listof 0, 30, 60, 90, 120 viewtype slider eligibility question 2 type choicequestionmodel id tracking_device query are you willing to wear a tracking device to monitor your dailywalking activity? candidates listof "yes, i'm willing to use a tracking device", "no, i'm notcomfortable using any tracking device" answer yes, i’m willing to use a tracking device eligibility question 3 type choicequestionmodel id participate query are you available and willing to commit to participating in thestudy for a specified duration? candidates listof "yes, i'm available and willing to commit", "no, i'm notavailable or willing to commit" answer yes, i’m available and willing to commit private val eligibilityquestions list<questionmodel<any>> = listof choicequestionmodel id = "average_walking_time", query = "how many minutes on average do you spend walking each day?", explanation = "unit minute", candidates = listof 0, 30, 60, 90, 120 , viewtype = slider , choicequestionmodel id = "tracking_device", query = "are you willing to wear a tracking device to monitor your daily walking activity?", candidates = listof "yes, i’m willing to use a tracking device", "no, i’m not comfortable using any tracking device" , answer = "yes, i’m willing to use a tracking device" , choicequestionmodel id = "participate", query = "are you available and willing to commit to participating in the study for a specified duration?", candidates = listof "yes, i’m available and willing to commit", "no, i’m not available or willing to commit" , answer = "yes, i’m available and willing to commit" you can make a pass condition for each question by setting the answer field a failed result means the participant is not eligible for the study after defining eligibility questions, the eligibility survey pages would look like as below set health data permissions you can request permission to collect health data from your study participants however, before requesting permissions, your app must first declare them in the manifest go to researchsample module > res > values in health_permissions xml, you can declare permissions to read or write data on health connect for steps, sleepsession, sleepstage, oxygensaturation, and bloodpressure data types notepermission to read and write heartrate data is already declared in the project <item>androidx health permission steps read</item> <item>androidx health permission steps write</item> <item>androidx health permission sleepsession read</item> <item>androidx health permission sleepsession write</item> <item>androidx health permission sleepstage read</item> <item>androidx health permission sleepstage write</item> <item>androidx health permission oxygensaturation read</item> <item>androidx health permission oxygensaturation write</item> <item>androidx health permission bloodpressure read</item> <item>androidx health permission bloodpressure write</item> tipfor more information, see the list of data types and permissions then, go back to healthstack sample folder in researchapplication kt, request permissions from the participants to collect required health data val healthdatarequired = listof "heartrate", "sleepsession", "sleepstage", "bloodpressure", "steps", "oxygensaturation" tipsee the list of health data types you can collect on health connect set sync interval and choose health data to display you can set the sync interval per health data type however, it is recommended to set a minimum interval of 15 minutes because the app is using android's workmanager tipto learn more about the workmanager, see periodicworkrequest in mainactivity kt, set healthdatasyncspecs as below health data type sync interval heartrate 15 minutes steps 20 hours sleepsession 1 day sleepstage 1 day oxygensaturation 30 minutes bloodpressure 30 minutes val healthdatasyncspecs = listof syncmanager healthdatasyncspec "heartrate", 15, timeunit minutes , syncmanager healthdatasyncspec "steps", 20, timeunit hours , syncmanager healthdatasyncspec "sleepsession", 1, timeunit days , syncmanager healthdatasyncspec "sleepstage", 1, timeunit days , syncmanager healthdatasyncspec "oxygensaturation", 30, timeunit minutes , syncmanager healthdatasyncspec "bloodpressure", 30, timeunit minutes , you can set which data type to display in the research app the status card for heart rate is already set to display to show other status cards, such as sleepsessionstatus, add them to the list of healthdatatodisplay val healthdatatodisplay = listof heartratestatus, sleepsessionstatus, taskstatus run the app, join the study and sync your health data build and run the app on a samsung galaxy mobile device ensure the samsung health app and health connect app is installed on the device and a galaxy watch is connected notereset the app to its initial state by clearing its data go to your phone's settings and then swipe to and tap apps select or search for the researchsample app tap storage, tap clear data, and then click ok in the research app, you can join the study by signing in with your google account after passing the eligibility survey, providing consent, and allowing data access to health connect the research app shows your heart rate data bpm and the time you spent sleeping hrs based on the data from your galaxy watch and mobile device notethe data shows and updates in the app based on the sync interval you set if you want the heart rate data to display immediately, you can measure your heart rate manually using the galaxy watch then, click the sync health data button in the research app's settings check health connect's recent logs if data is not showing or updating the web portal also displays and processes the data from the research to see the average heart rate data, go to the overview section scroll to the participant list table, then click the participant data row the participant management shows health data collected on average, such as heart rate create a survey task a survey is a sequence of questions that collect information from the participants in your study in this step, create a survey task and see the result from the web portal go to the study management section and expand the task management open the surveys tab and click the create survey button on the top right corner set survey title as daily survey then, write three questions as below after writing all the survey questions, click the publish button set the frequency as daily and the publish time as early as possible then, click the publish button on the bottom right corner you can find your survey task on the published list go to the research app and touch the refresh button next to upcoming tasks or today to see the survey you created answer and complete the survey task go back to the web portal click your survey task from the published list reload the web page or re-login to get the result you can see the survey report in the responses and analytics tab create an activity task activities allow researchers to collect specific types of data from users for this study, add an activity to collect measurements related to manual dexterity in study management, go to the activities tab and click the create activity button select motor for the activity category and choose tapping speed click the create button click the publish button on the task edit page set frequency as daily and publish time as early as possible then, click the publish button you can find your activity task on the published list in the research app, touch the refresh button to see the newly added activity open and perform the activity task in the web portal, click your activity task from the published list enter the participant id to see the collected data you're done! congratulations! you have successfully achieved the goal of this code lab now, you can create your own research app that can collect and process users’ health data, answers to survey and activity task results for research purposes by yourself! if you face any trouble, you may download this file research app complete code 4 09 mb to learn more, see samsung health stack