[Huawei Developers] shikkerimath:
Introduction

This article is based on Multiple HMS services application. I have created Hotel Booking application using HMS Kits. We need mobile app for reservation hotels when we are traveling from one place to another place.

In this article, I have implemented Analytics kit and Site Kit.

View attachment 5213995

Flutter setup

Refer this URL to setup Flutter.

Software Requirements

1. Android Studio 3.X

2. JDK 1.8 and later

3. SDK Platform 19 and later

4. Gradle 4.6 and later

Steps to integrate service

1. We need to register as a developer account in AppGallery Connect

2. Create an app by referring to Creating a Project and Creating an App in the Project

3. Set the data storage location based on current location.

4. Enabling Required Services: Analytics and Site Kit.

5. Generating a Signing Certificate Fingerprint.

6. Configuring the Signing Certificate Fingerprint.

7. Get your agconnect-services.json file to the app root directory.

Development Process

Create Application in Android Studio.

1. Create Flutter project.

2. App level gradle dependencies. Choose inside project Android > app > build.gradle.

apply plugin: 'com.android.application'
apply plugin: 'com.huawei.agconnect'

Root level gradle dependencies

maven {url 'https://developer.huawei.com/repo/'}
classpath 'com.huawei.agconnect:agcp:1.4.1.300'

Add the below permissions in Android Manifest file.

<manifest xlmns:android...>
...
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
...
</manifest>

3. Refer below URL for cross-platform plugins. Download required plugins.

https://developer.huawei.com/consum...y-V1/flutter-sdk-download-0000001051088628-V1

4. On your Flutter project directory find and open your pubspec.yaml file and add library to dependencies to download the package from pub.dev. Or if you downloaded the package from the HUAWEI Developer website, specify the library path on your local device. For both ways, after running pub get command, the plugin will be ready to use.

name: hotelbooking
description: A new Flutter application.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1

environment:
sdk: ">=2.7.0 <3.0.0"

dependencies:
flutter:
sdk: flutter
shared_preferences: ^0.5.12+4
bottom_navy_bar: ^5.6.0
cupertino_icons: ^1.0.0
provider: ^4.3.3

huawei_ads:
path: ../huawei_ads/
huawei_account:
path: ../huawei_account/
huawei_site:
path: ../huawei_site/
huawei_analytics:
path: ../huawei_analytics/
dev_dependencies:
flutter_test:
sdk: flutter

flutter:
uses-material-design: true
assets:
- assets/images/

5. We can check the plugins under External Libraries directory.

6. Open main.dart file to create UI and business logics.

Analytics kit

Account kit is valuable in terms of analysis and reporting that we use frequently in our application. Using analytics we can check user behavior custom events and predefined events.

Service Features

By integrating the HMS Core Analytics SDK, you can:

1. Collect and report custom events through coding.

2. Set a maximum of 25 user attributes.

3. Automate event collection and session calculation with predefined event IDs and parameters.

HUAWEI Analytics Kit identifies users and collects statistics on users by an anonymous application identifier (AAID). The AAID is reset in the following scenarios:

1. Uninstall or reinstall the app.

2. The user clears the app data.

After the AAID is reset, the user will be counted as a new user.

There are 3 types of events:

Automatically collected

Predefined

Custom

Automatically collected events are collected from the moment you enable the kit in your code. Event IDs are already reserved by HUAWEI Analytics Kit and cannot be reused.

Predefined events include their own Event IDs which are predefined by the HMS Core Analytics SDK based on common application scenarios. The ID of a custom event cannot be the same as a predefined event’s ID. If so, you will create a predefined event instead of a custom event.

Custom events are the events that you can create for your own requirements.

Integration

What is AAID?

Anonymous device ID opened to third-party apps. Each app is allocated with a unique AAID on the same device, so that statistics can be collected and analyzed for different apps.

void getAAID() async{
String aaid = await mAnalytics.getAAID();
print(aaid);
}

Custom Events

Such events can be used to meet personalized analysis requirements that cannot be met by automatically collected events and predefined events.

Note: The ID of a custom event cannot be the same as that of a predefined event. Otherwise, the custom event will be identified as a predefined event

Adding Custom Events

In AppGallery Connect from left side panel open Huawei Analytics > Management > Events

View attachment 5213997

void customEvent() async {
String name = "Custom";
dynamic value = {'customEvent': "custom Event posted"};
await _hmsAnalytics.onEvent(name, value);
}

Predefined Events

Such events have been predefined by the HMS Core Analytics SDK based on common application scenarios. It is recommended you use predefined event IDs for event collection and analysis.

void logEvent() async{
String name = HAEventType.SUBMITSCORE;
dynamic value = {HAParamType.SCORE: 15};
await mAnalytics.onEvent(name, value);
}

Site kit

This kit basically provide users with easy and reliable access to related locations and places. With the HMS Site kit we can provide them below features.

1. We can take place suggestions according to the keywords that we have determined.

2. According to the location of the user’s device, we can search for nearby places.

3. We can get detailed information about a location.

4. We can learn the human readable address information of a coordinate point.

5. We can learn the time period where a coordinate point is found.

HMS Site kit – Nearby Search

We can search for many places such as tourist attractions, restaurants, schools and hotels by entering information such as keywords, coordinates. Using this kit we can restrict to specific types using poiType, we can easily access many different information about places such as name, address, coordinates, phone numbers, pictures, address details. Within the Address Detail model, we can easily access information about the address piece by piece through different variables and change the way the address’ notation as we wish.

We need to create a NearbySearchRequest object to perform searching by keyword. We will perform the related search criteria on this NearbySearchRequest object.

While performing this operation, we need set many different criteria as we see in the code snippet. Let us examine the duties of these criteria one by one

1. Query: Used to specify the keyword that we will use during the search process.

2. Location: It is used to specify latitude and longitude values with a Coordinate object to ensure that search results are searched as closely to the location that we want.

3. Radius: It is used to make the search results within in a radius determined in meters. It can take values between 1 and 50000, and its default value is 50000.

4. CountryCode: It is using to limit search results according to certain country borders.

5. Language: It is used to specify the language that search results have to be returned. If this parameter is not specified, the language of the query field we have specified in the query field is accepted by default. In example code snippet in above, the language of device has been added automatically in order to get a healthy result.

6. PageSize: Results return with the Pagination structure. This parameter is used to determine the number of Sites to be found in each page.

7. PageIndex: It is used to specify the number of the page to be returned with the Pagination structure.

void loadNearBy(String value) async {
SearchService service = new SearchService();
NearbySearchRequest searchRequest = NearbySearchRequest();
searchRequest.language = "en";
searchRequest.query = value;
searchRequest.poiType = LocationType.RESTAURANT;
searchRequest.location = Coordinate(lat: 12.976507, lng: 77.7356);
searchRequest.pageIndex = 1;
searchRequest.pageSize = 15;
searchRequest.radius = 5000;
NearbySearchResponse response = await service.nearbySearch(searchRequest);
if (response != null) {
setState(() {
mSitesList = response.sites;
});
}
}

Result

View attachment 5213999

View attachment 5214001

Tips & Tricks

1. Download latest HMS Flutter plugin.

2. Enable Auto refresh in AppGallery connect it will automatically update events in console

3. Whenever you updated plugins, click on pug get.

Conclusion

We implemented simple hotel booking application using Analytics kit and Site kit in this article. We have learned how to record events and monitor them in AppGallery Connect and also we have learned how to integrated site kit and how nearby search will work.

Thank you for reading and if you have enjoyed this article, I would suggest you to implement this and provide your experience.

Reference

Analytics Kit URL

Site Kit URL

Read full article.