Intermediate: Integrating Huawei Awareness and Site Kit for Weather App in Xamarin(Android) — Part 2
Introduction
This application helps uses to get the weather information based on selected city and device location. It uses Huawei Site Kit for searching the place and Awareness Kit for getting the weather of the selected place.
Refer the Integrating Huawei Awareness Kit Site Kit for Weather App in Xamarin(Android) — Part 1
Let us start with the project configuration part for Huawei Site Kit:
Step 1: Enable Site Kit in Manage API menu.
Step 2: Download agconnect-services.json from App Gallery and place it inside project’s Asset folder.
Step 3: Create Xamarin Android Binding Libraries for Site Kit.
Step 4: Copy the site.dll file inside your project folder and add it to References (Right click on References > Add reference).
Now configuration part done for Site Kit.
Let us start with the implementation part:
Step 1: Create WeatherActivity.cs for getting the weather information on the basis of device current location and add it to listview.
WeatherActivity.cs
WeatherListAdapter.cs
weather_list.xml
weather_row.xml
WeatherData.cs
Step 2: Navigate to SearchPlaceActivity after Add button click on WeatherActivity.
Step 3: Copy the API Key from App Gallery and add it to strings.xml.
Step 4: Create SearchPlaceActivity.cs which will search for places and provides weather information of the selected place. It also adds the weather information to list in WeatherActivity.cs.
SearchPlaceActivity.cs
PlaceListAdapter.cs
SelectPlace.cs
Search_place.xml
place_row.xml
weather_info_layout.xml
Now Implementation part done.
Result
Tips and Tricks
1. Please enable the device location in Settings > Location.
2. Please enable location permission for HMS Core app.
Conclusion
In this article, we have learned to get the weather information based on search location like country, city, town etc. User can search the place and will get the weather information of particular searched place. It will provide weather information such as Temperature, Humidity, Rain forecast etc.
References