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



  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Popular Days

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 STF News
      View the full blog at its source
    • By BGR
      The Galaxy S22 might be the most exciting flagship series Samsung made, but it’s also marred by various controversies and issues. Chief among them is the throttling problem that impacted primarily Exynos 2200 versions of the Galaxy S22 in Korea and Europe. Samsung fixed the problem quickly, but the Galaxy S22 performance issues turned into a massive scandal in Korea, impacting sales. A new rumor now claims the Galaxy S22 FE will switch to MediaTek’s flagship System-on-Chip (SoC) offerings.
      Assuming the rumor is accurate, the Galaxy S22 might be the first Samsung flagship to pack a MediaTek processor. And the chip will likely replace Qualcomm or Exynos. The latter seems like the more likely victim considering the Galaxy S22 throttling issues.
      Don't Miss: Tuesday’s deals: $99 AirPods, $230 Apple Watch SE, Gillette sale, more Is there a Galaxy S22 FE phone?
      Several weeks before Samsung unveiled the Galaxy S22 series, the Galaxy S21 FE finally arrived. At the time, we told you that it might be better to hold off your purchase until the S22 rolled out.
      The cheaper Galaxy S21 FE delivered 2021 specs and a few compromises that let Samsung cut the phone’s price. The Galaxy S22 would offer better specs, with prices unchanged compared to its predecessor. Little did we know at the time that the Galaxy S22 would disappoint with the various issues Samsung had to deal with.
      Considering what has happened so far, it might make sense to see Samsung release a Galaxy S22 FE this year to “fix” the Galaxy S22 problems. Like last year, Samsung is yet to confirm the Galaxy S22’s Fan Edition. And in 2021, Samsung considered canceling the release, according to rumors. Samsung denied those reports, but it moved the Galaxy S21 FE release from summer 2021 to early 2022.
      Samsung Galaxy S22 Plus smartphone. Image source: Samsung The big MediaTek switch
      A new report from Business Korea name-checks the Galaxy S22 FE, claiming the phone will roll out in the second half of the year. Strangely enough, the blog also says the Galaxy S23 flagship will roll out in the second half of 2022, which must be a mistake in detailing Samsung’s purported plans for this year.
      Release dates aside, the blog notes that Samsung will use MediaTek’s System-on-Chip (SoC) for about half of the Galaxy S22 FE models and the Galaxy S23 phones sold in Asia. Samsung has only used MediaTek chips for its more affordable handsets in the past. This would be the first time Samsung goes for the top MediaTek SoC.
      Business Korea doesn’t say which SoC brand the MediaTek chip in the Galaxy S22 FE will replace. But the implication is that it’s the Exynos 2200 flagship. The report notes that Samsung is having a hard time promoting its SoC. And it so happens that the Galaxy S22 throttling issues have been spotted and fixed in Korea and Europe.
      The specs of MediaTek Dimensity 9000 flagship processor. Image source: MediaTek Will the Dimensity 9000 power the Galaxy S22 FE?
      MediaTek released the Dimenisity 9000 flagship SoC in mid-November 2019. At the time, we noted that MediaTek’s new chip achieved many “world firsts” in the industry and that it could be the kind of SoC that goes against the iPhone 13’s A15 Bionic.
      More interestingly, MediaTek mentioned Samsung among the Android vendors that will use the Dimenisity 9000 SoC. This was well before the Galaxy S21 FE and Galaxy S22 launch events. And it was several months before the Galaxy S22 throttling scandal.
      The Galaxy S22 performance issues were so significant in Korea that Samsung had to deal with them during its most recent shareholders meeting. Samsung apologized for the problem and said it hasn’t been cutting corners when designing the Galaxy S22.
      Pundits speculated that Samsung had to throttle performance to prevent the Galaxy S22 from overheating by running at peak capacity. Using the SoC at its max potential for a more extended period would also hurt the battery life. And they said Samsung did that so it could cut production costs.
      The Galaxy S22 phones will still throttle performance even after the fix is rolled out. But the user can at least have a say on when that throttling starts.
      Considering all that, the MediaTek high-end SoC might help Samsung deliver a better fix to its Galaxy S22 performance problem. After all, MediaTek teased that Samsung will use the Dimensity 9000 this year.
      The post Galaxy S22 FE might feature MediaTek’s flagship processor, rumor claims appeared first on BGR.
      View the full article
    • 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.





×
×
  • Create New...