Quantcast
Jump to content


Use Tizen Web To Measure Heart Rate With Galaxy Watches


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...
  • Similar Topics

    • By BGR
      Samsung’s Galaxy S23 series started shipping last week and appears to be a winner already. The phones are as fast as possible for 2023 Android flagships. The Galaxy S23 Ultra’s camera and battery life are impressive. More importantly, the Galaxy S23 phones aren’t more expensive than their predecessors, despite offering much better performance. Still, the phones are quite expensive. Samsung fans on a budget might want to wait for the price to drop — or for the cheaper Galaxy S23 FE to arrive.
      What’s great about Galaxy S23 performance so far is that we’re not seeing any of the issues that hurt the Galaxy S22 series last year. There’s no Exynos version of the handset, and Samsung isn’t throttling the phone. Nor is it cheating in benchmarks.
      If anything, the Galaxy S23 phones feature an even faster variant of the Snapdragon 8 Gen 2 chip that will power most 2023 Android flagships. And the same chip is available in all regions.
      Had Samsung followed Apple’s strategy, it could have easily turned the Galaxy S22 into a great budget alternative to the Galaxy S23. And Samsung did say during the Galaxy S23 event that it’ll continue selling the Galaxy S22. But those phones still rock the Snapdragon/Exynos combos of chips.
      Galaxy S23 price structure announced at Unpacked 2023. Image source: Samsung That’s to say the Galaxy S22 might have been a decent Galaxy S23 FE alternative. Samsung wouldn’t have needed to bring the Fan Edition back. As a reminder, there was no S22 FE variant last year.
      A Korean leaker (via SamMobile) claims that Samsung is making a Galaxy S23 FE this year. The phone should be more affordable than the $799 Galaxy S23, though the price hasn’t leaked. But the leaker says the phone will use the Snapdragon 8 Plus Gen 1 processor so Samsung can cut costs.
      As a reminder, the Snapdragon 8 Plus Gen 1 is a better variant of the regular Snapdragon chip that powers the Galaxy S22 phones. It’s the chip that Samsung used last year in all its Galaxy Z Fold 4 and Z Flip 4 foldables. It’s faster and less likely to overheat.
      Put differently, the Galaxy S23 FE won’t match the Galaxy S23’s performance, but it’ll still be a great smartphone that’s on par with last year’s flagships. Presumably. We still need to figure out what sort of specs the handset will offer and how much Samsung will charge for it.
      Don't Miss: $1,200 Galaxy S23 Ultra has a screen defect that Samsung calls normalThe post Cheaper Galaxy S23 FE set to feature Z Fold 4’s powerful processor appeared first on BGR.
      View the full article
    • By Samsung Newsroom
      View the full blog at its source
    • By BGR
      After the Galaxy S22 throttling disaster involving the Exynos 2200 chip earlier this year, we saw Samsung apologize to customers and investors. The company faced plenty of criticism and scrutiny, especially in its home market. Then, Samsung vowed to create a new set of flagship chips for its best phones. But the Galaxy S23 series that launches next year will probably run on Qualcomm’s latest Snapdragon processor.
      It’s all speculation at this point, but based on a significant announcement from Samsung and Qualcomm that claims the Korean giant will use more Snapdragon chips in its smartphones.
      Exynos is a major disappointment
      Samsung Exynos System-on-Chips (SoC) have never been able to match their Qualcomm counterparts, let alone outperform the iPhone. But Samsung kept using both Exynos and Snapdragon chips in its Galaxy S flagships for years. 
      The Exynos 2200 is the last such flagship Samsung-made chip, powering Galaxy S22 variants sold in certain markets. And the Exynos 2200 might be the final nail in the Exynos coffin. At least until Samsung reshuffles its chips teams and develops a new processor for high-end phones. The Galaxy S23 might come only in a Qualcomm Snapdragon variant as a result.

      As soon as the Galaxy S22 series came out, buyers discovered the Exynos 2200 processor would reduce performance to conserve battery life. This was more aggressive than on previous phones, implying the chip is prone to overheating when under heavy stress.
      The Exynos 2200 isn’t the first Samsung SoC to see criticism from buyers. Even Samsung mocked its previous Exynos variants last year while promoting the Exynos 2100. That was a chip that was supposed to fix all of the previous overheating and performance issues.
      Galaxy Z Fold 4 press image leak. Image source: 91mobiles/Evan Blass Galaxy S23 likely to be a Qualcomm-only affair
      During the Galaxy Z Fold 4 and Flip 4 rumors season, we learned the new foldables would come with Snapdragon chips inside. The phones would get the brand new Snapdragon 8 Plus Gen 1 SoC, leaks said. The 8 Plus Gen 1 is even more powerful and efficient than the 8 Gen 1 SoC that powers some Galaxy S22 variants.
      That meant the new Fold and Flip will not suffer the same throttling issues at the hand of the Exynos 2200. Or any version of it.
      Samsung, by the way, also mass-produced the 8 Gen 1 chip variant. But Qualcomm moved to TSMC for the 8 Plus Gen 1 SoC.
      Fast-forward to late July, and Qualcomm and Snapdragon issued a joint announcement. The two companies said they’ll extend their patent licensing agreement for seven years through 2030. More importantly, the announcement says that Snapdragon Platforms will power future Samsung Galaxy devices. The list includes “smartphones, PCs, tablets, extended reality, and more,” the press release says.
      Qualcomm didn’t list the Galaxy S23 as a beneficiary of the upcoming Snapdragon chips. But considering the context, it certainly seems like Snapdragon is a much better choice for Samsung’s future flagship. A report from an insider said earlier this month that Samsung would move to a Snapdragon-only strategy for the Galaxy S23 series.
      Also, we shouldn’t be surprised to see Samsung use only Snapdragon flagship SoCs in future flagships beyond the Galaxy S23. As much as Samsung might want to make a high-end chip of its own that can compete with Apple’s iPhone and Mac chips and Qualcomm’s Snapdragons, it won’t happen overnight.
      The post Galaxy S23 to feature Qualcomm’s newest Snapdragon processor appeared first on BGR.
      View the full article
    • By BGR
      The Galaxy S23 Ultra might feature a 200-megapixel primary camera, says an insider familiar with Samsung’s plans. Similar sensors are already in use or will come on other Android flagships. And it so happens that Samsung has a few Isocell sensors with 200 megapixels. But Ice Universe says it’s unclear which sensor will end up in the upcoming Galaxy S23 Ultra that will be released next year.
      Ice Universe often leaks details about unreleased Samsung devices on Twitter. While it might seem too early for Galaxy S23 Ultra rumors, the leaker already shared some camera specs on social media.
      He posted the image below, which reportedly comes from an upcoming Motorola flagship phone. The primary camera is a 200-megapixel sensor that the leaker identifies as HP1. That’s short for Isocell HP1, a 200-megapixel sensor that Samsung unveiled last year.
      In this context, Ice claimed that the Galaxy S23 Ultra will also feature a 200-megapixel sensor. However, it’s unclear which sensor Samsung will employ for its upcoming flagship. The HP1 isn’t the latest camera innovation from Samsung, as the company has an updated HP3 200-megapixel sensor in production.
      The leaker is also very vocal on Twitter when it comes to criticizing what he perceives as Samsung’s failures when it comes to mobile devices. He criticized the Galaxy S22 processor’s performance and One UI features in the past. More recently, he addressed issues with the Galaxy S22 camera’s performance.
      Samsung Isocell HP1 camera tech. Image source: Samsung Do phones need 200-megapixel sensors?
      Unlike its early days in the smartphone business, Samsung no longer increases the camera megapixel count on its smartphones just for the sake of bragging about specs. The Galaxy S20 Ultra came with a 108-megapixel sensor three years ago, but the upgrade was walked back with the Ultra’s larger camera setup. The Galaxy S22 Ultra also rocks a 108-megapixel wide-angle camera.
      If Ice’s claims are correct, the Galaxy S23 Ultra might be the first Galaxy S flagship to get a 200-megapixel camera.
      Samsung unveiled the Isocell HP1 sensor last year without specifying which smartphones would get the 200-megapixel camera. We now know Samsung never meant to use the camera on its 2022 flagships.
      A few weeks ago, Samsung unveiled the HP3 camera, which is also a 200-megapixel sensor. The video below explains the benefits of the sensor.
      In short, these cameras will improve resolution in well-lit environments. But they will automatically combine pixels and reduce the overall resolution to improve low-light and night photography.
      The HP3 sensor should deliver improved autofocus and better HDR algorithms. Moreover, Samsung also says the Isocell HP3 camera will support 8K video recording at up to 30fps.
      That said, the Isocell HP3 might not be the 200-megapixel camera that Samsung uses for the Galaxy S23 Ultra next year. Instead, Samsung might tweak it to create a custom version for the upcoming flagship. But that’s just speculation at this point.
      The Galaxy S23 series should launch in early 2023. By then, all of the camera specs will have leaked and we’ll know exactly what sort of camera experience Samsung plans to offer.
      The post Galaxy S23 Ultra to feature a 200-megapixel camera, insider claims appeared first on BGR.
      View the full article
    • By Samsung Newsroom
      View the full blog at its source





×
×
  • Create New...