Integrating Site Kit in Xamarin(Android)
--
Overview
Using Huawei Site Kit, developers can create an app which will provide users to find the places. Users can search for any place, schools or restaurants and app is providing the list of information.
This kit provides below features:
- Place Search: User can search for places based on keyword. It will return a list of places.
- Nearby Place Search: This feature can be used to get the nearby places based on user’s current location.
- Place Details: This feature can be used for getting the details of the place using its unique ID.
- Place Search Suggestion: This feature can be used to get the search suggestions on the basis of user input provided.
Let us start with the project configuration part:
Step 1: Create an app on App Gallery Connect.
Step 2: Enable the Site Kit in Manage APIs menu.
Step 3: Create Android Binding library for Xamarin project.
Step 4: Collect all those .dll files inside one folder as shown in below image.
Step 5: Integrate Xamarin Site Kit Libraries and make sure all .dll files should be there as shown in Step 4.
Step 6: 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 7: 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.
h) Add the SHA 256 key to App Gallery.
Step 8: 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 9: Download adconnect-services.json and add it to project Assets folder.
Step 10: Now click Build Solution in Build menu.
Let us start with the implementation part:
Step 1: Create a new class for reading agconnect-services.json file.
Step 2: Override the AttachBaseContext method in MainActivity to read the configuration file.
Step 3: Create UI inside activity_main.xml.
Step 4: Create TextSearchResultListener class that implements ISearchResultListener interface, which will be used for getting the result and set it to UI.
Step 5: Get the API key from AppGallary or agconnect-services.json file and define in MainActivity.cs.
Step 6: Instantiate the ISearchService object inside MainActivity.cs OnCreate() method.
Step 7: On Search button click, get the text from EditText, create the search request and call the place search API.
Result
Tips and Tricks
1. Do not forget to sign your .APK file with signing certificate.
2. Please make sure that GoogleGson.dll file is added in Reference folder.
Conclusion
This application helps for getting the place and its details on user’s search request. It will help to find school, hospital, restuarents etc.
Reference
https://developer.huawei.com/consumer/en/doc/HMS-Plugin-Guides-V1/placesearch-0000001050133866-V1