Huawei Developers
Published in

Huawei Developers

Set the barrier for WiFi Status by Huawei Awareness kit in Android (Kotlin)

Awareness Kit

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 can learn about the Wi-Fi Status Awareness feature. User can detect the Wi-Fi status of the device or can listen Wi-Fi status changes of the device, the following are types of APIs.

Capture API: User can obtain the current situation of Wi-Fi status. Example: once you click the button, you can check the Wi-Fi status of the device.

Barrier API: User can detect changes on Wi-Fi status. Example: when user opened Wi-Fi option or connected to any Wi-Fi point, we can detect it.

Here we can find the explanation for the real-time use of this feature, when user wants to download any application, such as game app, bank app, shopping app etc. User may cause some network problem. In such case, check that the user is connected to Wi-Fi while trying to download file or app. So, we can display a dialog to notify the user about that the device is not connected to any Wi-Fi network.


1. Any operating system (MacOS, Linux and Windows).

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

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

4. Minimum API Level 24 is required.

5. Required EMUI 9.0.0 and later version devices.

How to integrate HMS Dependencies

1. First register as Huawei developer and complete identity verification in Huawei developers website, refer to register a Huawei ID.

2. Create a project in android studio, refer Creating an Android Studio Project.

3. Generate a SHA-256 certificate fingerprint.

4. To generate SHA-256 certificate fingerprint. On right-upper corner of android project click Gradle, choose Project Name > Tasks > android, and then click signingReport, as follows.

Note: Project Name depends on the user created name.

5. Create an App in AppGallery Connect.

6. Download the agconnect-services.json file from App information, copy and paste in android Project under app directory, as follows.

7. Enter SHA-256 certificate fingerprint and click Save, as follows.

Note: Above steps from Step 1 to 7 is common for all Huawei Kits.

8. Click Manage APIs tab and enable Awareness Kit.

9. Add the below maven URL in build.gradle(Project) file under the repositories of buildscript, dependencies and allprojects, refer Add Configuration.

10. Add the below plugin and dependencies in build.gradle(Module) file.

11. Now Sync the gradle.

12. Add the required permission to the Manifestfile.xml file.

Let us move to development

I have created a project on Android studio with empty activity let’s start coding.

In the MainActivity.kt we can create the business logic.

Create separate class LogView.kt to find the logs.

In the activity_main.xml we can create the UI screen.


Tips and Tricks

1. Make sure you are already registered as Huawei developer.

2. Set minSDK version to 24 or later, otherwise you will get AndriodManifest merge issue.

3. Make sure you have added the agconnect-services.json file to app folder.

4. Make sure you have added SHA-256 fingerprint without fail.

5. Make sure all the dependencies are added properly.


In this article, we have learnt about the Wi-Fi Status Awareness feature. User can detect the Wi-Fi status of the device or can listen Wi-Fi status changes of the device.

I hope you have read this article. If you found it is helpful, please provide likes and comments.


Awareness Kit — Wi-Fi Status Awareness



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store