Interstitial ads in Xamarin.android

CastielTR 141 Reputation points
2021-07-03T08:51:27.917+00:00

I need to help how to entegry Int ad to my project. I have allready a banner ad but I cant add Int ad. I have few errors.
The error is :"Unable to instantiate abstract type or interface 'InterstitialAd"
The error code:"CS0144"
111533-1.png

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
4,918 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
7,523 questions
No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 43,931 Reputation points Microsoft Vendor
    2021-07-05T03:23:44.253+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    Because InterstitialAd is an abstract class, so we cannot new InterstitialAd() directly, we could create a new class to extend the InterstitialAd like following code.

    111635-image.png

    To achieve override method.

       public class MyInterstitialAd : InterstitialAd  
           {  
               private Context context;  
         
               public MyInterstitialAd(Context context)  
               {  
                   this.context = context;  
               }  
         
               public override string AdUnitId => throw new System.NotImplementedException();  
         
               public override FullScreenContentCallback FullScreenContentCallback { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); }  
               public override IOnPaidEventListener OnPaidEventListener { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); }  
         
               public override ResponseInfo ResponseInfo => throw new System.NotImplementedException();  
         
               public override void SetImmersiveMode(bool p0)  
               {  
                   throw new System.NotImplementedException();  
               }  
         
               public override void Show(Activity p0)  
               {  
                   throw new System.NotImplementedException();  
               }  
           }  
    

    Best Regards,

    Leon Lu


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    No comments

1 additional answer

Sort by: Most helpful
  1. Christopher Drosos 1 Reputation point
    2021-08-12T13:43:13.34+00:00

    Hello, thanks for this post, im trying too to create a new InterstitialAd from my old code. although i would need some help. i understand that from now on we have to override the method but how exactly we should do that?
    for example in the previous google ads version where override was not needed in order to show an add we have to do

    FullScreenAd = new InterstitialAd(this);
    FullScreenAd.AdUnitId = GetString(Resource.String.FullScreen_InterstitialDd_UunitId);
    FullScreenAd.AdListener = new AdListener(this);
    var adRequest = new AdRequest.Builder().Build();
    FullScreenAd.LoadAd(adRequest);
    FullScreenAd.Show();

    i cant exactly understand how i can now load and show ads and also here https://github.com/xamarin/GooglePlayServicesComponents/blob/main/samples/com.google.android.gms/play-services-ads/AdMobSample/InterstitialActivity.cs the sample is not updated,
    thanks