Quantcast
Jump to content

Use Tizen Web To Measure Heart Rate With Galaxy Watches


STF News
 Share

Recommended Posts

Health monitoring is a very popular feature in smart watches, and Tizen provides various APIs for this purpose. One API is HumanActivityMonitor, which allows users to monitor health by providing metrics such as heart rate, step count, and stress level.

This blog describes how to measure heart rate using this API. A sample web app combined with a widget is attached. This sample app measures heart rate and stores data by timestamp, and the widget shows the last measured heart rate. This blog focuses on how to measure heart rate using the device sensor, stored data, and communication between an app and a widget.

Create and run a Tizen project

1. Create a project in Tizen Studio. Because our target is an app that is combined with a widget, select the Widget template to create this project.

1.png

2. Add the Tizen Advanced UI (TAU) framework library to your project. You can create and manage various UI functionalities using the TAU library as an alternative to designing a UI with HTML and CSS components.

3. Link the tau.circle.min.css and tau.min.js in the app’s index.html file.

<link rel="stylesheet"
href="lib/tau/wearable/theme/default/tau.min.css"> 
<link rel="stylesheet" media="all and (-tizen-geometric-shape: circle)"
href="lib/tau/wearable/theme/default/tau.circle.min.css">
<script src="lib/tau/wearable/js/tau.min.js"> </script>

Measure heart rate and manage data

To measure heart rate using the HumanActivityMonitor API, add the following feature and privilege to the config.xml file:

<feature name="http://tizen.org/feature/humanactivitymonitor"/>
<tizen:privilege name="http://tizen.org/privilege/healthinfo"/>

Applications must request a user’s permission for privacy-related features. The tizen.ppm.requestPermission() method invokes the permission pop-up. When users give permission through the pop-up, they can then use the app features related to that privilege.

To measure heart rate, users must give permission to access the sensor using the following code snippet:

function onSuccess() {

    function onchangedCB(hrmInfo) {
        console.log(‘heart rate:’ + hrmInfo.heartRate);
        tizen.humanactivitymonitor.stop('HRM');
    }
    tizen.humanactivitymonitor.start('HRM', onchangedCB);
}

function onError(e) {
    console.log("error " + JSON.stringify(e));
}
tizen.ppm.requestPermission("http://tizen.org/privilege/healthinfo",onSuccess, onError);

Note that the HumanActivityMonitor API provides heart rate data directly in BPM (beats per minute). If you need the raw data of the sensor, you can use SensorHRMRawData.

The following screenshots show how to measure heart rate using the sample app:

2.png

The Web Storage API stores data in key-value format. This API offers two types of storage – Local and Session. In the sample, we use local storage, along with Date as key and heartRate as value. The Date key retrieves data according to date, week, and month. If you do not want to retrieve history according to date, you can use a different key, such as an integer value; just make sure there is no repetition in key value.

Create a Date object to get the current time stamp. localStorage.setItem() puts the key (Date)-value (heartRate) pair in local storage.

var date_key = new Date();
localStorage.setItem(date_key, hrmInfo.heartRate);

To retrieve data, filter according to the key. Date and month are retrieved from the Date object and filter data using localStorage.getItem(localStorage.key(i)).

var date = new Date();
var lastdate = new Date(localStorage.key(i));
if (lastdate.getDate() == date.getDate() 
&& lastdate.getMonth() == date.getMonth()) {
              console.log(localStorage.key(i)+ " :" + localStorage.getItem(localStorage.key(i)));

The following screenshots show how the history is categorized by day, week, and month:

31.png

Communication between the app and a widget

The sample widget shows the last measured heart rate value, and heart rate history is stored in the local storage of the web app. To establish communication between the app and widget, we’ll use the Preference API. The Preference API stores key-pair values, allowing web widgets to communicate with their parent apps.
In the app, data is stored with ‘KEY’:

tizen.preference.setValue('KEY', hrmInfo.heartRate);

In the widget, data is retrieved using the same ‘KEY’:

if (tizen.preference.exists('KEY')) {
    console.log(‘Last Measured: ‘ + tizen.preference.getValue('KEY'));
} 

The following screenshot of the sample widget shows the last measured heart rate:

4.png

Launch the app from a widget

To launch an app from widget, add the following privilege to config.xml:

<tizen:privilege 
name="http://tizen.org/privilege/application.launch"/>

To launch an app, provide your app ID in tizen.application.launch().

tizen.application.launch(YourAppID);

In the sample widget, the user taps Measure to launch the heart-rate measuring page or History to launch the heart-rate history page, and Preference can be used to determine which one is clicked. To implement, a different key-value pair is set for each page in the widget, and in the web app, key values are checked to detect which page is clicked.

5.png

For example, in the widget, the open_measure key is set to 1 to link to the Measure Page. The app then launches.

tizen.preference.setValue(‘open_measure’, 1);
tizen.application.launch(YourAppID);

The app checks for the open_measure key. If the key exists, the user is redirected to the Measure Page with tau.changePage().

window.onload = function() {
    if (tizen.preference.exists(' open_measure ')) {
        tau.changePage(YourPageID);
    }
}

You can also use the HumanActivityMonitor API to implement a step counter, stress level reading, GPS, and other features in your wearable device. Because enabling other features is similar to implementing the heart rate monitor, you can use this blog as a guide and the attached sampleHeartRateMonitor to enable a full range of health monitoring metrics to your Galaxy Watch.

View the full blog at its source

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Similar Topics

    • By SAMSUNG
      Enjoy an enhanced viewing experience with Neo QLED 8K. Its game-changing display technology brings you a step closer to reality through your TV screens. Greatness never ends, but evolves. #NeoQLED8K #SamsungTV
    • By Sharath
      Regular Security and Feature updates and more apps support - It lacks feature updates and apps. Samsung Smart TV lacks lot of apps compared to Android TVs or LG WebOS. Kindly consider
    • By Hemant
      Hey Guys, popular Indian OTT platform app MXPlayer is not there on Samsung tv app store. Can anyone develop the one and make it available for samsung TV's.
    • By STF News
      Samsung Electronics today announced that the HDR10+ Adaptive feature will be supported in Samsung TVs, which improves the HDR10+ viewing experience in customers’ homes regardless of the lighting conditions. HDR10+ Adaptive supports Filmmaker Mode and adapts to brighter rooms so customers can enjoy a true cinematic experience with HDR10+ movies and television programs in any environment at home. HDR10+ Adaptive will launch globally with Samsung’s upcoming QLED TV products.
       
      While viewing HDR content is typically optimal in a darkened environment, customers’ viewing environments may vary greatly depending on a wide array of factors, including room lighting, time of day, and proximity to windows. The HDR10+ Adaptive feature supports dynamic scene-by-scene optimization, following guidelines from the HDR10+ LLC, and can now adjust to any room lighting condition, further enhancing the HDR experience. This feature utilizes the TV’s light sensor and ensures that the screen brings to life the creative intent without any loss of details or contrast. All Prime Video HDR content is automatically delivered in HDR10+.
       
      HDR10+ Adaptive on Samsung QLED TVs also supports Filmmaker Mode, a display setting that Samsung – as a member of the UHD Alliance – developed in partnership with filmmakers, studios and consumer electronics manufacturers. Samsung and Amazon Prime Video teamed up to enable Filmmaker Mode and HDR10+ Adaptive for Prime Video customers.
       
      “We are always looking for new features and innovations that can help improve the customer experience,” said BA Winston, Global Head of Video Playback and Delivery at Amazon Prime Video. “With HDR10+ and Filmmaker mode, Prime Video content is optimized regardless of the viewing environment and customers can enjoy movies and TV shows the way the filmmakers intended.”
       
      More contents are becoming available in HDR10+ with Universal Pictures Home Entertainment (UPHE) and Samsung extending its technology partnership to include even more HDR10+ catalogues and new titles for distribution on OTT services around the world.
       
      “As consumers spend more time at home, Samsung has been looking for ways to enrich consumers’ entertainment experience in the comfort of their homes,” said Younghun Choi, Executive Vice President of Visual Display Business at Samsung Electronics. “We are delighted to offer smart picture quality solutions that will enhance consumers’ at-home HDR viewing experience, bringing original-quality cinematic experience to our consumers around the world.”
       
      “Samsung has demonstrated exceptional commitment in developing HDR10+ technology and bringing the industry together in support,” said Michael Aaronson, Senior Vice President, Digital Distribution, UPHE. “We are pleased to further expand our partnership with Samsung as we work to bring more titles into this advanced in-home viewing ecosystem to movie audiences worldwide.”
       
      UHD titles available on Prime Video also include HDR10+ so all Prime Video customers can enjoy the improved HDR experience with most Samsung QLED TVs regardless of room lighting conditions.
       
      For more information on Samsung TV, please visit www.samsung.com.
      View the full article
    • By STF News
      The Workout app was created to show how to implement a fully working application that supports running on wearable devices with Tizen.
      Workout is written in C# and uses the Xamarin.Forms and Tizen.CircularUI frameworks.

      Text
      Workout
      Overview
      This version of the application allows you to measure the following parameters while running:
      Running time Distance traveled Heart rate Pace Present effort In the summary of the training, the application also shows the most common range of effort.
      Read more
      In a series of blogs publishing this week, we will describe and show how key functionalities of the application are implemented, such as:
      Distance traveled Heart rate (intensity) Workout summary A detailed tutorial describing the application can be found on TizenSchool.org

      Distance
      Intensity You can download and test the app from the link below:
      https://github.com/Samsung/Tizen-CSharp-Samples/tree/master/Wearable/Workout
      In the next release of the application, it will collect workout data and give an insight into the history. It will also allow you to edit user profile settings such as age or the distance measurement unit.
      If you have an idea for functionality or have any comments about the application, let us know!
      View the full blog at its source
×
×
  • Create New...