Expert: Improving user experience by Huawei Awareness Kit Ambient Light feature in Xamarin(Android)
Huawei Awareness Ambient Light notifies us when the light intensity is low or high. It uses the device light sensor to work this feature. The unit of light intensity is lux. It provides Capture and Barrier API to get the light intensity value.
Capture API: This is used for getting the exact light intensity of the place where device is located.
Barrier API: This is used for setting the barrier. If we set the barrier for low lux value, then notification will be triggered if light intensity is below low lux value.
This application uses above feature and sends notification to the user if light intensity is lower than defined lux value. So that it improves the user experience.
Let us start with the project configuration part:
Step 1: Create an app on App Gallery Connect.
Step 2: Enable the Awareness Kit in Manage APIs menu.
Step 3: Create new Xamarin (Android) project.
Step 4: Change your app package name same as AppGallery app’s package name.
a) Right click on your app in Solution Explorer and select properties.
b) Select Android Manifest on lest side menu.
c) Change your Package name as shown in below image.
Step 5: Generate SHA 256 key.
a) Select Build Type as Release.
b) Right click on your app in Solution Explorer and select Archive.
c) If Archive is successful, click on Distribute button as shown in below image.
d) Select Ad Hoc.
e) Click Add Icon.
f) Enter the details in Create Android Keystore and click on Create button.
g) Double click on your created keystore and you will get your SHA 256 key. Save it.
f) Add the SHA 256 key to App Gallery.
Step 6: Sign the .APK file using the keystore for both Release and Debug configuration.
a) Right-click on your app in Solution Explorer and select properties.
b) Select Android Packaging Signing and add the Keystore file path and enter details as shown in image.
Step 7: Install Huawei Awareness Kit NuGet Package.
Step 8: Integrate HMS Core SDK.
Let us start with the implementation part:
Step 1: Create the activity_main.xml for adding Get Light Intensity and Add Light Intensity Barrier button.
Step 2: Add receiver in AndroidManifest.xml.
Step 3: Create a class which extends BroadcastReceiver and create the method for sending notification.
Step 4: Register the receiver inside MainActivity.cs OnCreate() method.
Step 5: Add the barrier after Add Light Intensity Barrier button click.
Now when the light intensity will be lower than LowLuxValue, it will send a notification to the user.
Step 6: Check the light intensity using the method GetLightIntensity() after Get Light Intensity button click.
Using this light intensity, user will know the exact light intensity present at that place.
Now Implementation part done.
Tips and Tricks
Please create notification channel before sending notification for the device API greater than 26.
In this article, we have learnt about improving user experience by Huawei Awareness Kit ambient light feature. It will notifying users when the light intensity is low at the place, so that user can switched on the Light or Torch.
Thanks for reading! If you enjoyed this story, please provide Likes and Comments.