Class AdMobAppOpenAdProvider
- Namespace
- VpnHood.AppLib.Ads.AdMob.Android
- Assembly
- VpnHood.AppLib.Ads.AdMob.Android.dll
Provides AdMob's app-open ads.
public class AdMobAppOpenAdProvider : IAdProvider, IDisposable
- Inheritance
-
AdMobAppOpenAdProvider
- Implements
- Inherited Members
Constructors
AdMobAppOpenAdProvider(string)
Provides AdMob's app-open ads.
public AdMobAppOpenAdProvider(string adUnitId)
Parameters
adUnitIdstringThe AdMob ad unit's ID; AdMobTestAdUnitIds has Google's test units.
Properties
AdLifeSpan
Gets how long a loaded ad may wait before it is shown.
public TimeSpan AdLifeSpan { get; }
Property Value
Remarks
It is 20 minutes.
AdLoadedTime
Gets when the ad loaded now was loaded, in UTC, or null where none is.
public DateTime? AdLoadedTime { get; }
Property Value
AdType
Gets the kind of ad the provider shows.
public AdType AdType { get; }
Property Value
NetworkName
Gets the ad network's name.
public string NetworkName { get; }
Property Value
Remarks
It is AdMob.
Methods
Create(string)
Creates a provider of AdMob's app-open ads.
public static AdMobAppOpenAdProvider Create(string adUnitId)
Parameters
adUnitIdstringThe AdMob ad unit's ID.
Returns
- AdMobAppOpenAdProvider
The provider.
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
Remarks
It does nothing: a loaded ad stays.
LoadAd(IUiContext, CancellationToken)
Loads an ad, to show it later.
public Task LoadAd(IUiContext uiContext, CancellationToken cancellationToken)
Parameters
uiContextIUiContextThe app's UI context.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task
A task that completes once an ad is loaded.
Remarks
It gathers the person's consent where one is due and starts AdMob's SDK, then loads the ad on the UI thread. A load that gets that far drops the ad loaded before; one that fails earlier, as for a destroyed activity, keeps it.
Exceptions
- NoFillAdException
The network had no ad to fill the request.
- LoadAdException
No ad could be loaded, as where the consent the network needs is missing.
- AdException
The network's SDK could not start, as AdMob's with no ad adapter.
- NotSupportedException
The network's SDK does not run on this Android version.
- TimeoutException
The network's SDK did not start in time.
- InvalidOperationException
The network's SDK did not start its initialization.
- OperationCanceledException
cancellationTokenwas canceled.- LoadAdException
The activity is destroyed, the consent AdMob needs is missing, or AdMob could not load an ad.
ShowAd(IUiContext, string?, CancellationToken)
Shows the ad loaded.
public Task<ShowAdResult> ShowAd(IUiContext uiContext, string? customData, CancellationToken cancellationToken)
Parameters
uiContextIUiContextThe app's UI context.
customDatastringThe data the ad network passes to the server's check of a rewarded ad, or null.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task<ShowAdResult>
A task whose result is how the ad ended.
Remarks
It shows the ad over the activity, and completes once the person has closed it; customData is
not used.
A show that starts drops the loaded ad however it ends; one that fails its checks keeps it. A cancel ends the
wait, not an ad already shown.
Exceptions
- ShowAdException
The ad could not be shown.
- RewardNotEarnedException
For a rewarded ad, the network did not confirm the reward in time after the ad closed.
- OperationCanceledException
cancellationTokenwas canceled.- ShowAdException
The activity is destroyed, no ad is loaded, or AdMob could not show it.