<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Francesco Romano on Medium]]></title>
        <description><![CDATA[Stories by Francesco Romano on Medium]]></description>
        <link>https://medium.com/@romanofranz?source=rss-263cf3ffa055------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ION1N1w-iaTMx_FaiJi20A.jpeg</url>
            <title>Stories by Francesco Romano on Medium</title>
            <link>https://medium.com/@romanofranz?source=rss-263cf3ffa055------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 20:39:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@romanofranz/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Tabletop mode on foldable devices]]></title>
            <link>https://medium.com/androiddevelopers/tabletop-mode-on-foldable-devices-d091b3c500b1?source=rss-263cf3ffa055------2</link>
            <guid isPermaLink="false">https://medium.com/p/d091b3c500b1</guid>
            <category><![CDATA[latest]]></category>
            <category><![CDATA[feautured]]></category>
            <category><![CDATA[large-screen]]></category>
            <dc:creator><![CDATA[Francesco Romano]]></dc:creator>
            <pubDate>Fri, 02 Jul 2021 15:57:16 GMT</pubDate>
            <atom:updated>2021-09-15T20:57:52.116Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4bfMdWeHGUkAhNlKuoucGw.png" /></figure><p><em>Unfolding your video player experience</em></p><p>Foldable devices offer users the possibility to do more with their phones, including innovations like the <em>Tabletop mode¹,</em> where the phone is placed on a surface with the hinge in a horizontal position, and the folding screen is in a partially opened state.</p><p>Tabletop mode is convenient when you want to use the phone without holding it in your hand. It’s great for watching media, making video calls, taking pictures and even gaming.</p><p>A great example is the optimization that the <a href="https://developer.android.com/stories/apps/google-duo">Google Duo team</a> did on their app to work well on tablets and foldable devices.</p><figure><img alt="Duo app before and after optimization" src="https://cdn-images-1.medium.com/max/1024/0*xoLo9WRPIs7U7cur" /><figcaption><em>Duo app before and after optimization</em></figcaption></figure><p>In this blog post you will learn a simple and efficient way to adapt your app’s layout when it runs on foldable devices.</p><p>The example is a simple media player that automatically adjusts its size to avoid having the fold in the middle of the image, and switches the location of its transport controls from embedded in-video when the screen is completely flat, to a separate panel when the device is folded, as shown in the video below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*u-VA2MuzyfPZ7lhCkHe2pg.gif" /><figcaption>Tabletop mode example on Samsung Galaxy Z Fold2 5G</figcaption></figure><h3>Ingredients</h3><p>The sample app uses <a href="https://github.com/google/ExoPlayer">Exoplayer</a>, a popular open source media playback library for Android, and these Jetpack components:</p><ul><li><a href="https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionLayout">MotionLayout</a>, a subclass of<a href="https://developer.android.com/training/constraint-layout"> ConstraintLayout</a>. It combines the flexibility of the parent class with smooth animations of the views during the transition from one posture to the other.</li><li><a href="https://developer.android.com/reference/androidx/constraintlayout/widget/ReactiveGuide">ReactiveGuide</a>, an invisible component that positions itself automatically when a SharedValue changes. It works with a <a href="https://developer.android.com/reference/androidx/constraintlayout/widget/Guideline">Guideline</a> helper.</li><li><a href="https://developer.android.com/jetpack/androidx/releases/window">WindowManager</a>, a library that helps app developers support new device form factors and provides a common API surface for different window features.</li></ul><p>To use these libraries you must add the<a href="https://android.devsite.corp.google.com/studio/build/dependencies?skip_cache=true#google-maven"> Google Maven repository</a> to your project and declare these dependencies:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/75097d05c4f50d5534d297c0011f09b5/href">https://medium.com/media/75097d05c4f50d5534d297c0011f09b5/href</a></iframe><h3>Layout</h3><p>Consider the layout of the video player Activity, the root element is a<a href="https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionLayout"> MotionLayout</a> that contains three child views.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ef019bb64fac055c1f31a493d180e0eb/href">https://medium.com/media/ef019bb64fac055c1f31a493d180e0eb/href</a></iframe><p>Two views are from the Exoplayer suite, which allows you to specify different layouts for the<a href="https://exoplayer.dev/doc/reference/com/google/android/exoplayer2/ui/PlayerView.html"> PlayerView</a> (the surface where the media is displayed) and the<a href="https://exoplayer.dev/doc/reference/com/google/android/exoplayer2/ui/PlayerControlView.html"> PlayerControlView</a> (the container of the playback controls).</p><p>The third view is a <a href="https://android.devsite.corp.google.com/reference/androidx/constraintlayout/widget/ReactiveGuide">ReactiveGuide</a>. It is placed between the other two views and works as a <a href="https://android.devsite.corp.google.com/reference/androidx/constraintlayout/widget/Guideline">Guideline</a>, a separator between the views.</p><p>The main<a href="https://exoplayer.dev/doc/reference/com/google/android/exoplayer2/ui/PlayerView.html"> PlayerView</a> is constrained to always be at the top of the ReactiveGuide. In this way, the layout transition will happen when you move the guide from the bottom of the screen to the position of the fold.</p><p>You might also want to constrain the control view to always be<strong> </strong>at the bottom of the ReactiveGuide. In this way the control view is hidden when the screen is flat, but it appears at the bottom part of the phone when the screen is partially open.</p><p>Note the attribute<a href="https://developer.android.com/reference/androidx/constraintlayout/widget/ConstraintLayout.LayoutParams#guideEnd"> <strong><em>layout_constraintGuide_end</em></strong></a> on line 28. This is the value you need to change to move the guideline. Since the ReactiveGuide is horizontal, this attribute represents the distance of the guideline to the bottom of the parent.</p><h3>Make your app fold-aware</h3><p>Now the most important part: how to know when the phone is in tabletop mode and how to get the position of the fold?</p><p>After it is initialized, the WindowManager library allows you to listen for layout changes by collecting the Flow&lt;<a href="https://developer.android.com/reference/androidx/window/layout/WindowLayoutInfo">WindowLayoutInfo</a>&gt; exposed by the function <a href="https://developer.android.com/reference/androidx/window/layout/WindowInfoRepository#windowLayoutInfo()">WindowInfoRepository.windowLayoutInfo()</a>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9c746770d974d0f78e84d22ab551ac8e/href">https://medium.com/media/9c746770d974d0f78e84d22ab551ac8e/href</a></iframe><p>If you want to know more about how to initialize and release an Exoplayer instance, see the <a href="https://developer.android.com/codelabs/exoplayer-intro">Exoplayer codelab</a>.</p><p>Every time you get a new layout information, you can query the display features and check if the device has a fold or hinge in the current display:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/18816430b1225571189decc43ef5c179/href">https://medium.com/media/18816430b1225571189decc43ef5c179/href</a></iframe><p>Note that if you don’t want to use Kotlin Flows, starting with the <a href="https://developer.android.com/jetpack/androidx/releases/window#1.0.0-alpha07">1.0.0-alpha07 release</a>, you can use the <strong><em>window-java</em></strong> artifact that exposes Java-friendly APIs to register and unregistered callbacks or the <strong><em>window-rxjava2</em></strong> and <strong><em>window-rxjava3</em></strong> artifacts for RxJava-adapted APIs.</p><p>A device can be used in tabletop mode if the orientation is horizontal and <a href="https://developer.android.com/reference/androidx/window/layout/FoldingFeature#isSeparating()">FoldingFeature.isSeparating()</a> returns true.</p><p>When this is the case, you can calculate the relative position of the fold and move the ReactiveGuide to that position, while moving it to 0 (bottom of the screen) otherwise.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/234ef7e99c01a2d2549529ed030f7cc4/href">https://medium.com/media/234ef7e99c01a2d2549529ed030f7cc4/href</a></iframe><p>When you call the function fireNewValue<strong><em> </em></strong>in this way, the library changes the<a href="https://developer.android.com/reference/androidx/constraintlayout/widget/ConstraintLayout.LayoutParams#guideEnd"> <strong><em>layout_constraintGuide_end</em></strong></a><strong><em> </em></strong>attribute. When the device is flat the whole screen should be reserved for the main PlayerView.</p><p>The last question is: where should you move the ReactiveGuide when the device is folded?</p><p>The <a href="https://developer.android.com/reference/androidx/window/layout/FoldingFeature"><strong><em>FoldingFeature</em></strong></a> object exposes the field <a href="https://developer.android.com/reference/androidx/window/layout/FoldingFeature#bounds()"><strong><em>bounds()</em></strong></a> to retrieve the bounding rectangle of the feature within the window coordinate space.</p><p>If you are dealing with a horizontal feature, most of the time the bounds will be represented by a Rect positioned in the vertical center of the screen, as wide as the screen and with height equal to the size of the hinge (this value could be 0 in case of a foldable screen or can be equal to the distance between the screens in dual screen devices).</p><p>If your app is in full screen mode, you can constrain the PlayerView to be at the top of <strong><em>FoldingFeatures.bounds.top</em></strong> and the ControlView at the bottom of <strong><em>FoldingFeatures.bounds.bottom</em></strong>.</p><p>In any other situation (not full screen) you need to account for the space occupied by the navigation bar and any other UI components on the screen.<br>In order to move the guideline, you must specify its distance from the bottom of the parent. One possible implementation of the function that calculates the right position for the ReactiveGuide looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/416957a9fd61107e4dd6c9b3d4af9ae3/href">https://medium.com/media/416957a9fd61107e4dd6c9b3d4af9ae3/href</a></iframe><h3>Summary</h3><p>In this article you learned how to improve the user experience for your media app on foldable devices by implementing a flexible layout that supports tabletop mode.</p><p>Stay tuned for the next articles on development guidance for different form factors!</p><h3>Additional resources</h3><ul><li><a href="https://developer.android.com/codelabs/exoplayer-intro">Exoplayer codelab</a></li><li><a href="https://www.youtube.com/watch?v=jIBNhxyciLQ">Tabletop demo</a></li><li><a href="https://developer.android.com/training/constraint-layout/foldables">Design for foldables</a></li><li><a href="https://developer.android.com/guide/topics/ui/foldables">Building apps for foldables</a></li><li><a href="https://github.com/androidx/androidx/tree/androidx-main/window">Jetpack WindowManager</a></li><li><a href="https://developer.android.com/training/constraint-layout/motionlayout">MotionLayout</a></li></ul><p>[1] Tabletop mode is also known as Flex mode on the Samsung Galaxy Z series foldable smartphones.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d091b3c500b1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/androiddevelopers/tabletop-mode-on-foldable-devices-d091b3c500b1">Tabletop mode on foldable devices</a> was originally published in <a href="https://medium.com/androiddevelopers">Android Developers</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to build a sport app powered by Smart Device Kits]]></title>
            <link>https://medium.com/huawei-developers/how-to-build-a-sport-app-powered-by-smart-devices-22f3dfc2b561?source=rss-263cf3ffa055------2</link>
            <guid isPermaLink="false">https://medium.com/p/22f3dfc2b561</guid>
            <category><![CDATA[ecosystem]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[smart-devices]]></category>
            <category><![CDATA[huawei]]></category>
            <category><![CDATA[hms]]></category>
            <dc:creator><![CDATA[Francesco Romano]]></dc:creator>
            <pubDate>Tue, 18 Aug 2020 08:11:46 GMT</pubDate>
            <atom:updated>2020-08-18T08:59:38.300Z</atom:updated>
            <content:encoded><![CDATA[<p>“Smart Device” Kits are part of Huawei HMS Core</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TkA0PlKvM_JmagfbnPy31A.jpeg" /></figure><p>After the first burst of innovation, the landscape of mobile app development has not changed that much during the last years. Despite the <strong>number of smart devices</strong> every person uses is growing quickly, the apps and services that we use daily are still struggling to share content across different devices in a seamless way.<br>Huawei’s strategy is to build an ecosystem of connected devices and related technologies to let developers build apps that are not confined anymore in the hardware limitation of a smartphone, but can be extended to create a smarter environment around the user.</p><h4>Imagine if you can build an app that is not only designed for your phone, but also for your home, your car or your gaming or sport equipment!</h4><p>As an interesting example, I’d like to show you how to build a sport app that take advantage of smart devices such as external cameras and smartwatches.</p><h3>Goal</h3><p>Practically, let’s build an Android app that is able to:</p><ul><li>Discover smart devices around you</li><li>Connect to the action camera and the smartwatch</li><li>Get live stream video from the camera</li><li>Get health data from the smartwatch</li><li>Overlay health data to the video stream</li><li>Enjoy the video :)</li></ul><h3>Preparation</h3><p>To help developers building such scenarios, Huawei is providing several powerful libraries. In this project we are going to use 2 of them in particular: <a href="https://developer.huawei.com/consumer/en/device-virtualization">Device Virtualization</a> (aka DV Kit) and <a href="https://developer.huawei.com/consumer/en/huaweihealth">HiHealth Kit</a>!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sTep44YuS8m9xNmZ6-FyCw.png" /></figure><p>The goal of DV Kit is to provide a single framework for a <strong>seamless multi-device interaction</strong>. There are 2 sets of libraries, one to be integrated in the Android app and another one in the Smart Device.</p><h4>On the app side, the advantage is that developers don’t need to write specific code to interface with external devices, but those are accessible in a similar way as internal resources!</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*mjSPszMp__hbVuXvkDezHQ.png" /></figure><p>HUAWEI HiHealth is an open platform facilitating easier data access and service aggregation of biometrics data, and consists of the HUAWEI Health app and HUAWEI HiHealth cloud.</p><p>The <strong>HUAWEI Health app</strong> is an official app from Huawei and comes pre-installed on all Huawei phones, providing users with diverse functions, such as workout data tracking, advanced fitness training, sleep monitoring, and healthy lifestyle services.</p><h3>What you will need</h3><ul><li>A Huawei smartphone equipped with Kirin 980 or later and running <a href="https://consumer.huawei.com/en/emui10-1/">EMUI 10.1+</a> (at the time of the article I recommend Huawei P40)</li><li>A <a href="https://consumer.huawei.com/en/wearables/">Huawei smartwatch</a> (I am using Huawei GT Watch Active 2)</li><li>An action camera compatible with <a href="https://developer.huawei.com/consumer/en/doc/development/connectivity-Guides/devicevirtualization-introduction">DV Kit</a> (for example <a href="https://driftinnovation.com/products/ghost-4K-plus">Drift Ghost 4K+</a>)</li><li>Love for sport and new technologies!</li></ul><h3>Implementation</h3><p>Security first, let’s apply for <strong>permissions</strong>.<br>DV kit is part of the family of platforms which are exclusively for businesses and hence any app has to be approved before it can access the APIs.</p><p>That’s why as a first step you need to register as a developer in <a href="https://developer.huawei.com/consumer/en/">Huawei’s portal</a>.<br>From the console then submit an app, upload your signing certificate fingerprint and and keep note of your app id. For more detailed steps see <a href="https://developer.huawei.com/consumer/en/doc/development/connectivity-Guides/devicevirtualization-preparation">environment preparation</a>.</p><p>Create a new project and add custom permissions in the manifest:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/37a9591e9cdb10cef145c769e6a19ca2/href">https://medium.com/media/37a9591e9cdb10cef145c769e6a19ca2/href</a></iframe><p>Those permissions are checked at runtime and verified by Huawei Cloud, for this reason the app must be<strong> signed with the same certificate</strong> previously uploaded in the console.<br>Also, the <em>app id</em> must be specified in the manifest:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c9ae134679cf94b706436128208ba929/href">https://medium.com/media/c9ae134679cf94b706436128208ba929/href</a></iframe><p>Some Android standard permissions are also needed to access the Camera API, to record audio and to access body sensors data:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5f0f25d8846da3034c814b5f02c902bd/href">https://medium.com/media/5f0f25d8846da3034c814b5f02c902bd/href</a></iframe><p>Now it’s time to include DV kit dependencies in the gradle file. Add the repository in <strong>both</strong> buildscript and allprojects locations:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7d30afd932d09ef808142290e0650e6d/href">https://medium.com/media/7d30afd932d09ef808142290e0650e6d/href</a></iframe><p>While in the app-level gradle file, configure the build dependencies:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4710e21c286280ad4be675c248493872/href">https://medium.com/media/4710e21c286280ad4be675c248493872/href</a></iframe><p>You can find all the sdk versions published <a href="https://developer.huawei.com/consumer/en/doc/development/connectivity-Guides/devicevirtualization-guide#h2-1579232232971">here</a>.</p><p><strong>HiHealth Kit</strong> comes in the form of a <em>jar</em> file that you need to manually download from the<a href="https://developer.huawei.com/consumer/en/doc/development/health-Library/31206"> developer website</a> and add in the <em>libs</em> folder.<br>For exploration purposes, you can use the debug version, but in order to publish an app that uses HiHealth APIs you firstly need to apply for those permissions, similarly to DV kit.<br>If you want to join the developer program see <a href="https://developer.huawei.com/consumer/en/doc/development/huaweihealth-Guides/overview-0000001050060843#EN-US_TOPIC_0000001050060843__section15952595575">HiHealth data access introduction.</a><br>Once you got the artifact, add the gradle dependencies in this way:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/da69d06d9effefd38b5aa57293288fc0/href">https://medium.com/media/da69d06d9effefd38b5aa57293288fc0/href</a></iframe><h3>Integrating Device Virtualization</h3><p>In an over-simplified scenario we will need just 2 objects, a <a href="https://developer.huawei.com/consumer/en/doc/development/connectivity-References/devicevirtualization-virtualdevicemanager">VirtualDeviceManager</a> that handles the lifecycle of the service and a collection of <a href="https://developer.huawei.com/consumer/en/doc/development/connectivity-References/devicevirtualization-virtualdevice">VirtualDevice</a> objects to keep track of the smart devices around the smartphone.</p><p>For simplicity I will use an HashMap where the key is the device id. It can be declared like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/89d15aee8a8b5fb13821b9880c73897d/href">https://medium.com/media/89d15aee8a8b5fb13821b9880c73897d/href</a></iframe><p>Then let’s initialize the DVKit service, calling the following function in the <em>onCreate</em> phase:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3ca523efc2ae70832bbf50bb23af144f/href">https://medium.com/media/3ca523efc2ae70832bbf50bb23af144f/href</a></iframe><p>You may notice that we need to define 2 additional objects to specify what happens when a new device gets discovered and when a new capability is enabled.<br>In the first case, we just want to add the discovered device to our collection (ideally avoiding duplicates), we can do that by implementing the <a href="https://developer.huawei.com/consumer/en/doc/development/connectivity-References/devicevirtualization-api">IDiscoveryCallback</a>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1fbec61f618c53409678717a411c4581/href">https://medium.com/media/1fbec61f618c53409678717a411c4581/href</a></iframe><p>In the second case, the <a href="https://developer.huawei.com/consumer/en/doc/development/connectivity-References/devicevirtualization-api">IVirtualDeviceObserver</a> will notify that a new capability has been detected. In particular, we want to use the just discovered smart camera, enable it and start a new Activity passing the camera id as parameter.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a0867eeb73565d4e3e86fcf368569b8f/href">https://medium.com/media/a0867eeb73565d4e3e86fcf368569b8f/href</a></iframe><p>That’s it! Now the smartphone is connected with the external camera and we can work with it just like we would do with the phone’s internal one.<br>Let’s see how.</p><blockquote>For simplicity, we will use the camera in a separate Activity, an interesting use case is to put the phone in the pocket once it is connected to the external camera (mounted on the helmet or bike) while keeping the live stream ongoing. In this case it’s better to use a Service instead, the code is anyway very similar.</blockquote><p>As already said, once the external camera has been connected, it can be used just like any other camera, consider it a <a href="https://developer.android.com/reference/android/hardware/camera2/CameraDevice">CameraDevice</a> object from Android Camera 2 API.</p><p>The Activity got the cameraId as a parameter, another property that will be useful is the range of available frames target, keeping this in mind, the function to open the camera will look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/058478c12e164ceb0e0c797ff68004a7/href">https://medium.com/media/058478c12e164ceb0e0c797ff68004a7/href</a></iframe><p>The <a href="https://developer.android.com/reference/android/hardware/camera2/CameraDevice.StateCallback">stateCallback</a> needs to be initialized:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3b759c73f00d58ad85a75899c2e7bfa5/href">https://medium.com/media/3b759c73f00d58ad85a75899c2e7bfa5/href</a></iframe><p>Now, the tough part. This article is not meant to be an exhaustive guide on how to work with cameras in Android, many things can be done and my suggestion is to give a look at the <a href="https://developer.android.com/guide/topics/media/camera">official documentation</a>.<br>However it’s important to say that we need to define a <a href="https://developer.android.com/reference/android/hardware/camera2/CaptureRequest">CaptureRequest</a> to be used in a <a href="https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession">CameraCaptureSession</a>.<br>So the <em>startPreview(cameraDevice)</em> looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/05fb3a4588a84cd930515fe0227c9a3a/href">https://medium.com/media/05fb3a4588a84cd930515fe0227c9a3a/href</a></iframe><p>Since we want to add an additional layer with biometrics data on the top of the video stream, we are going to use a custom <a href="https://developer.android.com/reference/android/view/SurfaceView">SurfaceView</a> which also needs to be an <a href="https://developer.android.com/reference/android/opengl/GLSurfaceView.Renderer">OpenGL Render</a>. Let’s call this class <em>OverlayView</em> and let’s explore its main characteristics.<br>From the previously defined <em>startPreview(cameraDevice)</em> function we know that the class holds a Surface, images drawn to this Surface can be attached to an OpenGL ES texture. <br>Without going too deep in the OpenGL ES functionality, let’s assume we have a <em>draw(data: BiometricData)</em> function that simply draws a Sprite icon and a Text on the surface.</p><p>Now It’s time to retrieve this real time data from the smartwatch!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/1*EzxMJkcgyCrjJ6lnrH3ZXw.gif" /></figure><h3>Integrating HiHealth</h3><p>We are now going to use the Java APIs to retrieve data from the HUAWEI Health app, which can be synchronized in real time with the smartwatch.</p><p>User needs to grant permissions to let third-party apps accessing health data by accepting a dialog box. The dialog can be shown using the <em>requestAuthorization(context, writingPermissions, readingPermissions,listener)</em> method from <a href="https://developer.huawei.com/consumer/en/doc/development/health-References/hihealthauth">HiHealthAuth class</a>.<br>In our case, a simple method would be this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3e9688b9f5a470b5dc0b2050321d96c3/href">https://medium.com/media/3e9688b9f5a470b5dc0b2050321d96c3/href</a></iframe><p>In particular, we are asking the user to let our app accessing the heart rate and other real time sport data. All the possible read/write permissions are listed <a href="https://developer.huawei.com/consumer/en/doc/development/health-References/hihealthopenpermissiontype">here</a>.</p><p>As a starting point, let’s see how to read <strong>heart rate information</strong>. Additional data can be retrieved with a similar approach.<br>It’s time to meet our special guest, the <a href="https://developer.huawei.com/consumer/en/doc/development/health-References/hihealthdatastore">HiHealthDataStore</a>. This object is the main interface between our app and user’s data.</p><p>It has 2 convenient method that we are going to use: <em>startReadingHeartRate</em> and <em>stopReadingHeartRate</em>.<br>The results are in JSON format, it’s common to define a data class to store the information and to take advantage of the <a href="https://github.com/google/gson">Gson</a> deserializer:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a4c084f85b9c423509a2adf6c1c465d5/href">https://medium.com/media/a4c084f85b9c423509a2adf6c1c465d5/href</a></iframe><p>Getting the desired data now looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e7dd0d44c030e8020dd0057b96a90cca/href">https://medium.com/media/e7dd0d44c030e8020dd0057b96a90cca/href</a></iframe><p>The <em>heartBeatRate</em> value can be consumed by an observer that will notify our <em>OverlayView</em>, which will eventually draw the data on screen.<br>Another interesting method is <em>startRealTimeSportData: </em>it can be used in a similar way with an <a href="https://developer.huawei.com/consumer/en/doc/development/health-References/hisportdatacallback">HiSportDataCallback</a> to obtain a Bundle of data, including speed, calories burnt, altitude and many others. A complete list of all the keywords can be found <a href="https://developer.huawei.com/consumer/en/doc/development/health-References/hihealthKitconstant">here</a>.</p><h3>Conclusions and next steps</h3><p>This is an end to this article but beginning of our journey as there will be more content on how to build innovative multi-device use cases using our HMS Kits!</p><h4>If you want to see a wonderful example you can check the <a href="http://www.driftlife.co/watch/37641">Drift Life App</a>, which fully leverages DV Kit and HiHealth to bring an innovative experience to their users.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/1*zZGkxd6RWkGPF_Sxc2OwMQ.gif" /></figure><p>By the way, this is just one of the possible scenarios that can be realized using newest HMS Smart Device kits. Huawei Smart Device kits are in active development and more and more scenarios will be supported in future. I would like to hear your ideas and feature requests!</p><blockquote>A further investigation could be the real-time processing of the video stream using <a href="https://developer.huawei.com/consumer/en/hiai">HiAI</a>: Huawei’s powerful tool to run <strong>neural networks on device</strong>. If the smartphone is going to be the center of a connected smart enviroment, better to learn how to fully leverage the potential of its “brain”!</blockquote><p>I hope to have intrigued you with this article, if you are interested enough to try developing an app that uses these technologies, do not hesitate to contact <a href="http://francesco.romano1@huawei.com/">me</a> or ask in the comment section!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=22f3dfc2b561" width="1" height="1" alt=""><hr><p><a href="https://medium.com/huawei-developers/how-to-build-a-sport-app-powered-by-smart-devices-22f3dfc2b561">How to build a sport app powered by Smart Device Kits</a> was originally published in <a href="https://medium.com/huawei-developers">Huawei Developers</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>