Expert: Xamarin Android Weather App highlights Rewards ads and Banner Ads

HMS Ads kit is powered by Huawei which allows the developer to monetization services such as Reward and Banner ads. HUAWEI Ads Publisher Service is a monetization service that leverages Huawei’s extensive data capabilities to display targeted, high-quality ad content in your application to the vast user base of Huawei devices.

Manoj Kumar
5 min readMar 19, 2021

Overview

In this article, I will create a demo app along with the integration of HMS Ads Kit which is based on Cross platform Technology Xamarin. I have implemented Huawei Ads Kit. So the developer can easily monetise their efforts using Reward Ads and Interstitial Ads.

Ads Kit Service Introduction

HMS Ads kit is powered by Huawei which allows the developer to monetization services such as Reward and Banner ads. HUAWEI Ads Publisher Service is a monetization service that leverages Huawei’s extensive data capabilities to display targeted, high-quality ad content in your application to the vast user base of Huawei devices.

Prerequisite

1. Xamarin Framework

2. Huawei phone

3. Visual Studio 2019

Xamarin Ads Kit Setup Process

1. Download Xamarin Plugin all the aar and zip files from below url:

https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Library-V1/xamarin-sdk-download-0000001050175494-V1#EN-US_TOPIC_0000001050175494__section1134316505481

2. Open the XAdsIdentifier-3.4.35.300.sln solution in Visual Studio.

3. Navigate to Solution Explore and right click on jar Add > Exsiting Item and choose aar file which download in Step 1.

4. Choose aar file from download location.

5. Right click on added aar file, then choose Properties > Build Action > LibraryProjectZip

Note: Repeat Step 3 & 4 for all aar file.

6. Build the Library and make dll files.

Xamarin App Development

1. Open Visual Studio 2019 and Create A New Project.

2. Navigate to Solution Explore > Project > Add > Add New Folder.

3. Navigate to Folder(created) > Add > Add Existing and add all dll files.

4. Right-click on Properties, choose Build Action > None

5. Navigate to Solution Explore > Project > Reference > Right Click > Add References, then navigate to Browse and add all dll files from recently added folder.

6. Added reference, then click OK.

Ads Kit Integration

Banner Ads Integration Procedure

Add BannerView in either of the following methods to display banner ads:

1. Edit the XML layout file.

Add BannerView to the XML layout file, and set the hwads:adId and hwads:bannerSize attributes to the ad slot ID and ad size respectively.

The following sample code shows how to add BannerView to an XML layout file:

2. The following sample code shows how to obtain BannerView:

BannerView defaultBannerView = FindViewById<BannerView>(Resource.Id.hw_banner_view);

3. Use coding.

Add BannerView to the code, and set the ad slot ID and ad size.

4. (Optional) Listen for ad events.

You can listen for ad events using the methods in the AdListener class.

LoginActivity.cs

This activity perform all the operation regarding login with Huawei Id along with banner ads display in bottom of the screen.

Rewarded Ad Integration Procedure

1. Add a rewarded ad object.

Add a RewardAd object. The sample code is as follows:

// "testx9dtjwj8hp" is the test slot ID.

RewardAd rewardAd = new RewardAd(this, "testx9dtjwj8hp");

2. Load an ad.

Call the LoadAd method of the RewardAd object to load an ad. The sample code is as follows:

3. Display an ad.

Call the IsLoaded property to check whether an ad has been loaded. If the ad has been loaded, call the Show() method of the RewardAd object to display the ad.

The sample code is as follows:

MainActivity.cs

This activity perform all the operation regarding Weather Awareness api like current city weather and display Rewarded Ad.

Xamarin App Build Result

1. Navigate to Solution Explore > Project > Right Click > Archive/View Archive to generate SHA-256 for build release and Click on Distribute.

2. Choose Distribution Channel > Ad Hoc to sign apk.

3. Choose Demo keystore to release apk.

4. Build succeed and Save apk file.

5. Finally here is the result.

Tips and Tricks

1. On mobile phones whose value of targetSdkVersionis 28 or later, ad video assets may fail to be downloaded. In this case, you need to configure the app to allow HTTP network requests. For details, please refer to Configuring Network Permissions.

2. ads-installreferrer SDK: provided for third-party ad platforms or third-party tracking platforms. They can use install referrers to help advertisers track app conversion channels and perform in-depth conversion effectiveness analysis.

Conclusion

In this article, we have learned how to integrate HMS Ads Kit in Xamarin based Android application. We can display ads in the application.

Thanks for reading this article.

Be sure to like and comments to this article, if you found it helpful. It means a lot to me.

References

https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Guides/service-introduction-0000001050178531

https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Library-V1/xamarin-sdk-download-0000001050175494-V1#EN-US_TOPIC_0000001050175494__section1134316505481

--

--