Body Weight Exercise Application Using HMS Awareness Kit

Sanghati Mukherjee
Huawei Developers
Published in
5 min readNov 6, 2020

Huawei Awareness Kit provides our application to obtain information such as current time, location, behavior, audio device status, ambient light, weather, and nearby beacons. Using this information we can get an advantage over user’s current situation more efficiently and can manipulate data for better user experience.

In this article, we will use weather information using HMS Awareness Kit for manipulating warm up exercise for user.

Demo

In the above demo, the warm up exercise for user will get change according to the weather condition. Here the weather condition is divided into two parts:

1) Outdoor warm up exercise: When the weather condition is okay such as sunny or not raining, then the warm up exercise will get change to running.

2) Inside warm up exercise: When the weather condition is not okay such as raining or snow fall, then the warm up exercise will get change to invisible jumping rope, burpee and squats.

By this way we are providing user a better experience without avoiding any exercise due to certain condition. It’s a win-win situation for developers to not to lose any user due to bad user experience.

Prerequisite

1) Must have a Huawei Developer Account.

2) Must have a Huawei phone with HMS 4.0.0.300 or later.

3) Must have a laptop or desktop with Android Studio, Jdk 1.8, SDK platform 26 and Gradle 4.6 installed.

Things Need To Be Done

1) Create a project in android studio.

2) Get the SHA Key. For getting the SHA key we can refer to this article.

3) Create an app in the Huawei AppGallery connect.

4) Enable awareness kit setting in Manage APIs section.

5) Provide the SHA Key in App Information Section.

6) Provide storage location.

7) After completing all the above points we need to download the agconnect-services.json from App Information Section. Copy and paste the Json file in the app folder of the android project.

8) Enter the below maven url inside the repositories of buildscript and allprojects (project build.gradle file):

maven { url ‘http://developer.huawei.com/repo/’ }

9) Enter the below plugin in the app build.gradle file:

apply plugin: ‘com.huawei.agconnect’

10) Enter the below HMS Push kit dependencies in the dependencies section:

implementation ‘com.huawei.hms:awareness:1.0.6.301’

11) Enter the below permission in android manifest file

<uses-permission android:name=”android.permission.ACCESS_FINE_LOCATION” />

12) Now Sync the gradle.

Weather Awareness

It is used for providing weather information such as current day or next seven days weather information of a specific device location. It does not support barrier information or function.

The above code is used to get the weather information such as sunny, rain, cloudy etc. Using this information we will manipulate the warm up exercise and show user the list of exercise.

getWeatherByDevice

This method is used to obtain the weather information using the current location of a device. There are some restriction using this method:

1) The total number of capture API calls every 5 seconds cannot exceed 20

2) The total number of capture API calls every hour cannot exceed 1000

3) This function is available only on device with API level 24 or later

4) ACCESS_FINE_LOCATION permission is needed in android manifest file.

WeatherStatus

This is the main API where we will fetch the weather id. Using this id we will manipulate the exercise. This API contain five methods:

1) getAqi()

2) getWeatherSituation()

3) getDailyWeather()

4) getHourlyWeather()

5) getLiveInfo()

Here we will use getHourlyWeather to obtain weather information in the next 24 hours. The information which we will be able to fetch are weather ID, time, temperature and rainfall probability.

Weather Id

It is a constant value, which describes the weather information corresponding to different values of weatherId. The constant values are:

+-------------------------------+-------+--------------------------+
| Name | Value | Description |
+-------------------------------+-------+--------------------------+
| SUNNY | 1 | Sunny. |
| MOSTLY_SUNNY | 2 | Mostly sunny. |
| PARTLY_SUNNY | 3 | Partly sunny. |
| INTERMITTENT_CLOUDS | 4 | Intermittent clouds. |
| HAZY_SUNSHINE | 5 | Hazy sunshine. |
| MOSTLY_CLOUDY | 6 | Mostly cloudy. |
| CLOUDY | 7 | Cloudy. |
| DREARY | 8 | Dreary. |
| FOG | 11 | Foggy. |
| SHOWERS | 12 | Shower. |
| MOSTLY_CLOUDY_WITH_SHOWERS | 13 | Mostly cloudy with showers. |
| PARTLY_SUNNY_WITH_SHOWERS | 14 | Partly sunny with showers. |
| T_STORMS | 15 | Thunderstorm. |
| MOSTLY_CLOUDY_WITH_T_STORMS | 16 | Mostly cloudy with thunderstorms. |
| PARTLY_SUNNY_WITH_T_STORMS | 17 | Partly sunny with thunderstorms. |
| RAIN | 18 | Rain. |
| FLURRIES | 19 | Light snow. |
| MOSTLY_CLOUDY_WITH_FLURRIES | 20 | Mostly cloudy with light snow. |
| PARTLY_SUNNY_WITH_FLURRIES | 21 | Partly sunny with light snow. |
| SNOW | 22 | Snow. |
| MOSTLY_CLOUDY_WITH_SNOW | 23 | Mostly cloudy with snow |
| ICE | 24 | Ice. |
| SLEET | 25 | Sleet. |
| FREEZING_RAIN | 26 | Ice rain. |
| RAIN_AND_SNOW | 29 | Sleet. |
| HOT | 30 | Hot. |
| COLD | 31 | Cold. |
| WINDY | 32 | Windy. |
| CLEAR | 33 | Sunny. |
| MOSTLY_CLEAR | 34 | Mostly clear. |
| PARTLY_CLOUDY | 35 | Partly cloudy. |
| INTERMITTENT_CLOUDS_2 | 36 | Intermittent clouds. |
| HAZY_MOONLIGHT | 37 | Hazy sunshine. |
| MOSTLY_CLOUDY_2 | 38 | Mostly cloudy. |
| PARTLY_CLOUDY_WITH_SHOWERS | 39 | Partly cloudy with showers. |
| MOSTLY_CLOUDY_WITH_SHOWERS_2 | 40 | Mostly cloudy with showers. |
| PARTLY_CLOUDY_WITH_T_STORMS | 41 | Partly cloudy with thunderstorms. |
| MOSTLY_CLOUDY_WITH_T_STORMS_2 | 42 | Most cloudy with thunderstorms. |
| MOSTLY_CLOUDY_WITH_FLURRIES_2 | 43 | Mostly cloudy with flurries. |
| MOSTLY_CLOUDY_WITH_SNOW_2 | 44 | Mostly cloudy with snow. |
+-------------------------------+-------+-------------------------+

Opening YouTube Video in HMS devices

public static void watchYoutubeVideo(Context context, String id){
try {
Intent webIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com/watch?v=" + id));
context.startActivity(webIntent);
} catch (ActivityNotFoundException ex) {}
}

The Id here is YouTube Id.

CountDownTime

As the name implies to counts down the time specified in milliseconds.

Timer

In case user go for run we need to have a timer to capture the duration of its completion.

What we learn?

We learn how to manipulate data using HMS Weather Awareness Kit and also situation where we need the most.

For more reference

1)https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides-V5/service-introduction-0000001050031140-V5

2)https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides-V5/weather-awareness-0000001050121038-V5

--

--