Introduction
In this article, will explain how to develop heart reading health application integration on Harmony lite wearable. Following are the APIs we are going to integrate with this application.
1) On Body status API: To detect the watch is tied with the user’s wrist.
2) Heart rate API: To read the heart rate.
3) Memory storage API: To cache the previous reading.
4) Keep screen on API: To keep the screen on for 5 minutes.
Moving to this article if you are new to the Harmony platform, you can check this article: Huawei Lite Wearable Application Development using HUAWEI DevEco Studio (HamonyOS)
Requirements
1) DevEco IDE
2) Lite wearable watch (Can use simulator also)
Steps to create the project
1) Open the DevEco studio, choose File > New > New Project to create the new project.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
2) Select the Lite Wearable project and select Template.
3) Enter Project Name and Package name, and then click Finish.
Flow chart
Here is the flow chart of the application that we are going to integrate.
Integration process
Step 1: Design the UI
As the first step, we can create a UI that contains two texts, one for the heading and another for showing the result.
index.html
Code:
<div class="container" onswipe="touchMove">
<text class="title"> Your Heart Rate is </text>
<text class="title2"> {{title}} bpm </text>
</div>
index.css
Code:
.container {
display: flex;
justify-content: center;
align-items: center;
left: 0px;
top: 0px;
width: 454px;
height: 454px;
flex-direction:column;
}
.title {
font-size: 30px;
text-align: center;
width: 200px;
height: 100px;
}
.title2 {
font-size: 30px;
text-align: center;
width: 400px;
height: 40px;
flex-wrap:wrap;
background-color: cornflowerblue;
}
Run the application, and you can see an output as given below.
Step 2: Integrate On Body State API
Now we will move to the API part. Firstly we have to add code to check if the user is tied with the watch or not. For that, we have on body state API.
More details, you can check https://forums.developer.huawei.com/forumPortal/en/topic/0202454821219350012
Can we use any other IDE ?
Related
Map Kit has various SDKs and APIs. One of them is JavaScript API which is a solution for web applications and cross platforms.
What does Map Kit JavaScript API provide?
It provides the basic map display, map interaction, route planning, place search, geocoding, and other functions to meet requirements of most developers.
Which browsers are supported?
Currently, JavaScript APIs support the following browsers:
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
What are the prerequisites to use Map Kit JavaScript API?
Before using the service, you need to apply for an API key on the HUAWEI Developer website.
How to integrate basic capabilities?
First thing is to copy API Key from the developer console:
Code:
AppGallery Connect > Your App > Develop > Overview > App Information > API key
We need to provide the HUAWEI Map Kit API file. The API key must be encoded. You can encode it programatically or you can try out online tools to do it manually.
Code:
<script src="https://mapapi.cloud.huawei.com/mapjs/v1/api/js?callback=initMap&key=API KEY"></script>
Create map element in the body:
Code:
<div id="map"></div>
Initialize the map. The following sample code is to create a map with Paris as the center and a zoom level of 8:
Code:
function initMap() {
const mapOptions = {};
mapOptions.center = {lat: 48.856613, lng: 2.352222};
mapOptions.zoom = 8;
mapOptions.language='ENG';
const map = new HWMapJsSDK.HWMap(document.getElementById('map'), mapOptions);
}
Add a marker:
Code:
const mMarker = new HWMapJsSDK.HWMarker({
map,
position: {lat: 48.85, lng: 2.35},
label: 'A',
icon: {
opacity: 0.5
}
});
Show information window when clicking on marker:
Code:
const infoWindow = new HWMapJsSDK.HWInfoWindow({
map,
position: 10,
content: 'This is a InfoWindow.',
offset: [0, -40],
});
mMarker.addListener('click', () => {
infoWindow.open(mMarker);
});
Sample code is available on my GitHub page: /onurkenis/ionic-hms-map-demo
Hi,
Map kit Api will support navigation.how to show shortest path.
Mre information like this, you can visit HUAWEI Developer Forum
Do you want to test a web page whether is functional or not before providing solutions to CPs you can use Quick App IDE for testing just in a few steps:
1) Create a new project by using File > New Project > New QuickApp Project... direction. Enter App Name, Package Name and select "Hello World" template.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
2) Open "hello.ux" file folder and paste following script. You only need to change loadUrl adress that you want to test e.g. https://developer.huawei.com/consumer/en/doc/
Code:
template>
<div class="doc-page">
<!-- Replace the link to the HTML5 app -->
<web class="web-page" src="{{loadUrl}}" trustedurl="{{list}}" onpagestart="onPageStart" onpagefinish="onPageFinish"
onmessage="onMessage" ontitlereceive="onTitleReceive"
onerror="onError" id="web"
supportzoom="{{supportZoom}}"
wideviewport="{{wideViewport}}}"
overviewmodeinload="{{overViewModeLoad}}"
useragent="{{ua}}"
allowthirdpartycookies="{{allowThirdPartyCookies}}">
</web>
</div>
</template>
<style>
.doc-page {
flex-direction: column;
flex-direction: column;
justify-content: center;
align-content: center;
align-items: center;
width: 100%;
height: 100%;
position: fixed;
}
.web-page {
width: 100%;
height: 100%;
}
</style>
<script>
import router from "@system.router";
export default {
props: ['websrc'],
data: {
title: "",
// TODO Replace the link to the H5 app
loadUrl: "https://developer.huawei.com/consumer/en/doc/",
// Attribute allowthirdpartycookies, indicates whether cookies can be delivered in cross-domain mode.
// If you need login Google Account or Other Account, Please set TRUE.
allowThirdPartyCookies: true,
//Attribute supportzoom, indicates whether the H5 page can be zoomed with gestures.
supportZoom:true,
wideViewport:true,
overViewModeLoad:true,
ua:"default",
// Here the whitelist settings, when the loading page has multiple addresses, such as the successful loading of the login address and the inconsistent entry address, it needs to set the whitelist to do so.
list: ["new RegExp('https?.*')"]
},
onInit() {
console.info('onInit: ');
},
onPageStart(e) {
console.info('pagestart: ' + e.url)
},
// Each page switch triggers
onPageFinish(e) {
console.info('pagefinish: ' + e.url, e.canBack, e.canForward);
},
onTitleReceive(e) {
this.title = e.title;
},
onError(e) {
console.info('pageError : ' + e.errorMsg)
},
onMessage(e) {
console.info('onmessage e = ' + e.message + ", url = " + e.url);
},
onShow: function () {
console.info(" onshow");
},
onHide: function () {
console.info(" onHide");
},
onBackPress() {
console.log('onBackPress')
this.$element('web').canBack({
callback: function (e) {
if (e) {
console.log('web back')
this.$element('web').back()
} else {
console.log('router back')
router.back()
}
}.bind(this)
})
return true
},
}
</script>
3) Put your app icon under Common folder. E.g. developer.png
4) Open manifest.json file and paste follwing script and change icon name with the file that you uploaded under Common folder.
Code:
{
"package": "com.testapp.huwei",
"name": "TestApp",
"versionName": "1.0.0",
"versionCode": 1,
"icon": "/Common/developer.png",
"minPlatformVersion": 1060,
"features": [
{
"name": "system.configuration"
},
{
"name": "system.calendar"
},
{
"name": "system.prompt"
},
{
"name": "system.router"
}
],
"permissions": [
{
"origin": "*"
}
],
"config": {},
"router": {
"entry": "Hello",
"pages": {
"Hello": {
"component": "hello"
}
}
},
"display": {
"titleBar":false
}
}
4) Create .rpk package by using Build > Run Release direction.
5) Accept IDE to create a signature file for your app.
6) com.testapp.huawei_release_1.0.0.rpk package has been generated and ready for test.
For more details...
Links
How can we convert an H5 app into a Quick App with Online Conversion:
https://forums.developer.huawei.com/forumPortal/en/topicview?tid=0201240455899740095&fid=0101188387844930001
After the quick app web component is used to pack an HTML5 app into a quick app, the original web page does not provide the function of returning to the home page. In an HTML5 quick app, users want to have an entry for returning to the home page when browsing any HTML5 page.
To implement this requirement, perform the following steps:
1. Define the loadUrl variable under data in the page script. This variable is used to store the URL of the HTML5 web page. In this demo, the Huawei official website is used as the home page entry.
HTML:
export default {
props: ['websrc'],
data: {
title: "",
// TODO Replace the link to the H5 app
loadUrl: "http://www.huawei.com/en",
allowThirdPartyCookies: true,
//Attribute supportzoom, indicates whether the H5 page can be zoomed with gestures.
supportZoom: true,
wideViewport: true,
overViewModeLoad: true,
},
}
2. Modify template code.
Bind the src attribute of web in template to the variable loadUrl defined in step 1.
Listen to the pagestart event of the web component, that is, onpagestart in the code.
Add the entry layout of returning to the home page, which needs product design. This demo uses an image as an example.
The sample code is as follows. Pay attention to the text in red to see the modification points.
HTML:
<template>
<div class="doc-page">
<image src="/Common/main.png" onclick="goMain"></image>
<web class="web-page" src="{{loadUrl}}" trustedurl="{{list}}" onpagestart="onPageStart" onpagefinish="onPageFinish"
onmessage="onMessage" ontitlereceive="onTitleReceive" onerror="onError" id="web" supportzoom="{{supportZoom}}"
wideviewport="{{wideViewport}}}" overviewmodeinload="{{overViewModeLoad}}" useragent="{{userAgent}}"
Precautions:
The event callback methods goMain and onPageStart in the preceding code must be defined in the script.
The value of src in the image component must be replaced with the actual image path in the project.
3. Modify the code in the script. The following code needs to be modified:
In the callback method onPageStart of the web component, assign the value of url (indicating the URL of the current page) to loadUrl.
HTML:
onPageStart(e) {
console.info('pagestart: ' + e.url)
this.loadUrl=e.url;
},
l In the goMain method, assign the home page URL to loadUrl.
HTML:
goMain: function () {
console.log("goMain :");
this.loadUrl = "https://www.huawei.com/en";
},
Then, you can click HUAWEI on the screen to go to the Huawei official website.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Article Introduction
In this article, I have explained how to develop a calendar application for Huawei Lite Wearable device using Huawei DevEco Studio and using JS language in Harmony OS. Calendar provides options to swipe to desired day, month and year.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Huawei Lite Wearable
Requirements
1) DevEco IDE
2) Lite wearable watch (Can use simulator also)
New Project (Lite Wearable)
After installation of DevEco Studio, make new project.
Select Lite Wearable in Device and select Empty Feature Ability in Template.
After the project is created, its directory as shown in image.
Integration process
Design the UI
Step 1: Add background image.
As the first step, we can create a UI that contains calendar text boxes which will filled by the dates. Create and add the background image for calculator screen using stack component.
index.hml
Code:
<stack class="stack">
<image src='/common/calendarbackground.png' class="background"></image>
</stack>
index.css
Code:
.background {
width:454px;
height:454px;
}
.stack {
width: 454px;
height: 454px;
justify-content: center;
}
Step 2: Add row of days in a week in highlighted text boxes.
Create and add a row for days from Sunday to Saturday with letters “S, M, T, W, T, F, and S”.
index.hml
Code:
<div class="days" for="{{value in days}}" tid="id">
<text class="days">{{value}}</text>
</div><strong> </strong>
index.js
Code:
days: ["S", "M", "T", "W", "T", "F", "S"],
Step 3: Add UI for calendar dates
Create and add row for 7 days and 6 weeks in a month. We need 7x6 matrix of text boxes. Use loop rendering for the boxes since all are similar boxes
Code:
<div class="containerRow" for="{{valueWeek in weeks}}" onswipe="touchMove">
<div class="datestext" for="{{value in valueWeek}}" tid="id">
<text class="datestext">{{value}}
</text>
</div>
</div>
Code:
.datestext {
display: flex;
font-size: 8px;
text-align: center;
width: 55px;
height: 40px;
border-width: 1px;
border-color: #414343;
color: #414343;
background-color: #e6e6e6;
}
More details, you can check https://forums.developer.huawei.com/forumPortal/en/topic/0201459080286730034
Gotta say DevCo and Harmony are getting better every day......I mean look at all this amazing applications we are able to develop and intergrate
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
IntroductionIn this article, I have explained how to develop a stopwatch application for Huawei Lite Wearable Device.
Huawei Lite Wearable watch application development supports JS language with the support of HTML tags and CSS for styling layouts.
Requirements
Dev Eco Studio IDE
Lite wearable watch or simulator
New Project For Lite WearableYou can create a new project for Lite Wearable in 3 steps as follows.
Step -1
Step-2
Step-3
Implementation
UI Design :
I used 2 basic components for the application. I used a text for the duration and 3 images to start, pause and finish the time.
index.hml:
Code:
<stack class="stack">
<image src='/common/Mirage.png' class="background"></image>
<div class="container" onswipe="touchMove">
<text class="title">
{{time}}
</text>
<div class="row">
<image src="{{src}}" class="stopWatchButtons" onclick="startOrPause"></image>
<image src="/common/stop-button.png" class="stopWatchButtons" onclick="reset"></image>
</div>
</div>
</stack>
index.css:
Code:
@import '../../common/style.css';
.stopWatchButtons{
width: 64px;
height: 64px;
margin: 5px;
}
Code Part :
setInterval function sets a repeating timer for the system to repeatedly execute a function at a fixed interval. In the remaining part, I calculated using the starting time and the elapsed time. I converted this time into hours, minutes, seconds and milliseconds and transferred it to the text.
index.js:
Code:
function timeToString(time) {
// milliseconds to hours
let diffInHrs = time / 3600000;
let hh = Math.floor(diffInHrs);
// hours to minutes
let diffInMin = (diffInHrs - hh) * 60;
let mm = Math.floor(diffInMin);
// minutes to seconds
let diffInSec = (diffInMin - mm) * 60;
let ss = Math.floor(diffInSec);
// seconds to milliseconds
let diffInMs = (diffInSec - ss) * 100;
let ms = Math.floor(diffInMs);
let formattedHH = padL(hh,2,0)
let formattedMM = padL(mm,2,0)
let formattedSS = padL(ss,2,0)
let formattedMS = padL(ms,2,0)
return `${formattedHH}:${formattedMM}:${formattedSS}:${formattedMS}`;
}
function padL(a,b,c) { //string/number,length=2,char=0
return (new Array(b || 2).join(c || 0) + a).slice(-b)
}
Output
ConclusionIf you are going to make an application related to the stopwatch, you can simply use it this way. In this article, we learned how to develop applications for Harmony OS using Dev Eco Studio.
Well explained, can we send notification?
sujith.e said:
Well explained, can we send notification?
Click to expand...
Click to collapse
First of all I'm sorry for the late reply. Yes, you can using App-to-app Message Communication. Related documents are below.
Android: https://developer.huawei.com/consum...ty-Guides/phone-send-message-0000001051059209
Lite Wearable: https://developer.huawei.com/consum...es/fitnesswatch-send-message-0000001052460491
Thank you!