Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70432

Capacitor AdMob Plugin doesn't display correctly

$
0
0

@alokjkumar97 wrote:

Ionic v5 with Angular using https://github.com/rahadur/capacitor-admob

Hi I have followed the set up guide and am seeing a splashscreen at the bottom of the page for banner ads:

image

I also get this view whilst the app is starting up - if there’s any way to prevent the splashscreen in the corner that would be great

image

I have abstracted the plugin to a separate service called admob.service.ts as so:

To initialize the plugin:

  constructor(private platform: Platform) {
    if(this.platform.is('mobileweb') || this.platform.is('desktop')) {
      // pass
    } else if(this.platform.is('ios')) {
      AdMob.initialize('ca-app-pub-ios-key');
    } else {
      AdMob.initialize('ca-app-pub-android-key');
    }
  }

To show a banner ad:

  public async showBannerAd(position: any = AdPosition.BOTTOM_CENTER, adSize: any = AdSize.SMART_BANNER): Promise<any> {
    if(this.platform.is('mobileweb') || this.platform.is('desktop')) { return; }
    // This is a test ID
    const adId = 'ca-app-pub-3940256099942544/6300978111';
    const options: AdOptions = {
      adId: adId,
      adSize: adSize,
      position: position,
      hasTabBar: false,
    }

    AdMob.addListener('onAddFailedToLoad', async (info: any) => {
      this.removeBannerAd();
    });

    return AdMob.showBanner(options)
  }

I had to upgrade the plugin to AndroidX which is where I think the problem is:

AdMob.java

import androidx.coordinatorlayout.widget.CoordinatorLayout;

bridge_layout_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.getcapacitor.BridgeActivity"
    >

    <WebView
        android:id="@+id/webview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

Appreciate any thoughts

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70432

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>