Expert: Xamarin Android Weather App highlights Weather Awareness API and Login with Huawei Id

HMS Account Kit allows you to connect to the Huawei ecosystem using your HUAWEI ID from a range of devices, such as mobile phones, tablets, and smart screens.

Manoj Kumar
6 min readFeb 12, 2021

Overview

In this article, I will create a demo app along with the integration of HMS Account & Awareness Kit which is based on Cross platform Technology Xamarin. User can easily login with Huawei Id and get the details of their city weather information. I have implemented Huawei Id for login and Weather Awareness for weather forecasting.

Account Kit Service Introduction

HMS Account Kit allows you to connect to the Huawei ecosystem using your HUAWEI ID from a range of devices, such as mobile phones, tablets, and smart screens.

It’s a simple, secure, and quick sign-in and authorization functions. Instead of entering accounts and passwords and waiting for authentication.

Complies with international standards and protocols such as OAuth2.0 and OpenID Connect, and supports two-factor authentication (password authentication and mobile number authentication) to ensure high security.

Weather Awareness Service Introduction

HMS Weather Awareness Kit allows your app with the ability to obtain contextual information including users’ current time, location, behavior, audio device status, ambient light, weather, and nearby beacons. Your app can gain insight into a user’s current situation more efficiently, making it possible to deliver a smarter, more considerate user experience.

Prerequisite

1. Xamarin Framework

2. Huawei phone

3. Visual Studio 2019

App Gallery Integration process

1. Sign In and Create or Choose a project on AppGallery Connect portal.

2. Add SHA-256 key.

3. Navigate to Project settings and download the configuration file.

4. Navigate to General Information, and then provide Data Storage location.

5. Navigate to Manage APIs and enable APIs which require by application.

Xamarin Account Kit Setup Process

1. Download Xamarin Plugin all the aar and zip files from below url:

https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Library-V1/xamarin-sdk-download-0000001050768441-V1

2. Open the XHwid-5.03.302.sln solution in Visual Studio.

Xamarin Weather Awareness Kit Setup Process

1. Download Xamarin Plugin all the aar and zip files from below url:

https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Library-V1/xamarin-0000001061535799-V1

2. Open the XAwarness-1.0.7.303.sln solution in Visual Studio.

3. Navigate to Solution Explore and right click on jar Add > Exsiting Item and choose aar file which download in Step 1.

4. Right click on added aar file, then choose Properties > Build Action > LibraryProjectZip

Note: Repeat Step 3 & 4 for all aar file.

5. Build the Library and make dll files.

Xamarin App Development

1. Open Visual Studio 2019 and Create A New Project.

2. Navigate to Solution Explore > Project > Assets > Add Json file.

3. Navigate to Solution Explore > Project > Add > Add New Folder.

4. Navigate to Folder(created) > Add > Add Existing and add all dll files.

5. Right-click on Properties, choose Build Action > None

6. Navigate to Solution Explore > Project > Reference > Right Click > Add References, then navigate to Browse and add all dll files from recently added folder.

7. Added reference, then click OK.

Account Kit Integration

Development Procedure

1. Call the HuaweiIdAuthParamsHelper.SetAuthorizationCode method to send an authorization request.

2. Call the GetService method of HuaweiIdAuthManager to initialize the IHuaweiIdAuthService object.

IHuaweiIdAuthService mAuthManager;

mAuthManager = HuaweiIdAuthManager.GetService(this, mAuthParam);

3. Call the IHuaweiIdAuthService.SignInIntent method to bring up the HUAWEI ID authorization & sign-in screen.

StartActivityForResult(mAuthManager.SignInIntent, 8888);

4. Process the result after the authorization & sign-in is complete.

LoginActivity.cs

This activity perform all the operation regarding login with Huawei Id.

Weather Awareness API Integration

Assigning Permissions in the Manifest File

Before calling the weather awareness capability, assign required permissions in the manifest file.

<!-- Location permission. This permission is sensitive and needs to be dynamically applied for in the code after being declared. -->

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

Developing Capabilities

Call the weather capability API through the Capture Client object.

MainActivity.cs

This activity perform all the operation regarding Weather Awareness api like current city weather and other information.

Xamarin App Build Result

1. Navigate to Solution Explore > Project > Right Click > Archive/View Archive to generate SHA-256 for build release and Click on Distribute.

2. Choose Distribution Channel > Ad Hoc to sign apk.

3. Choose Demo keystore to release apk.

4. Build succeed and Save apk file.

5. Finally here is the result.

Tips and Tricks

1. Awareness Kit supports wearable Android devices, but HUAWEI HMS Core 4.0 is not deployed on devices other than mobile phones. Therefore, wearable devices are not supported currently.

2. Cloud capabilities are required to sense time information and weather.

3. 10012: HMS Core does not have the behaviour recognition permission.

Conclusion

In this article, we have learned how to integrate HMS Weather Awareness and Account Kit in Xamarin based Android application. User can easily login and check weather forecast.

Thanks for reading this article.

Be sure to like and comments to this article, if you found it helpful. It means a lot to me.

References

https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Guides/sign-in-idtoken-0000001051086088

https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Guides/service-introduction-0000001062540020

--

--

Manoj Kumar
Manoj Kumar

No responses yet