2017-11-05 2 views
0

Ich habe meiner Website-App bereits ein Admob-Banner hinzugefügt, indem ich den Anweisungen eines Youtube-Videos folge. Jetzt möchte ich eine Interstitial-Anzeige hinzufügen, irgendwelche Ratschläge?wie admob Interstitial ad meine webview app mit android studio hinzufügen?

Das ist mein activity_main.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout 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" 
    xmlns:ads="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.mscs.lim.MainActivity"> 

    <WebView 
     android:layout_width="368dp" 
     android:layout_height="495dp" 
     android:layout_centerHorizontal="true" 
     android:id="@+id/webView" 
     tools:layout_editor_absoluteX="8dp" 
     tools:layout_editor_absoluteY="8dp" /> 

    <com.google.android.gms.ads.AdView 
     android:id="@+id/adView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_alignParentBottom="true" 
     ads:adSize="BANNER" 
     ads:adUnitId="ca-app-pub-4873432488084596/8921164178"> 
    </com.google.android.gms.ads.AdView> 

</android.support.constraint.ConstraintLayout> 

Antwort

0

Angenommen, es gibt 3 Aktivitäten und die Eröffnungssequenz ist wie folgt:

Activity_A -> Activity_B -> Activity_C.

Jetzt möchten Sie Interstitial Ad zwischen Activity_B und Activity_C anzeigen. Zuerst wurde die Interstitial-Anzeige in Activity_A geladen und dann in Activity_C aufgerufen (oder angezeigt). Sie können wie folgt oben tun:

In Activity_A heißt MainActivity Code wie folgt hinzu:

public void showme(){ 

     mInterstitialAd = new InterstitialAd(this); 
     mInterstitialAd.setAdUnitId(getString(R.string.interstitial_full_screen)); 
     AdRequest adRequest = new AdRequest.Builder() 
       .build(); 
     mInterstitialAd.loadAd(adRequest); 

     mInterstitialAd.setAdListener(new AdListener() 
     { 

      @Override 
      public void onAdClosed() 
      { 
       //reload interstitial 
       AdRequest adRequest = new AdRequest.Builder() 
//      .addTestDevice("YOUR_DEVICE_ID") 
         .build(); 
       mInterstitialAd.loadAd(adRequest); 
      } 
     }); 
    } 

    public static void showInterstitial() { 
     if (mInterstitialAd.isLoaded()) { 
      mInterstitialAd.show(); 
     } 
    } 

Rufen Sie diese showme() in Activity_A innerhalb OnCreate.

In Activity_C Paste unter Code in OnCreate:

Activity_A.showInterstitial(); 

Mein Rat ist, Interstitial-Anzeigen in erster Aktivität (das heißt MainActivity) und dann rufen Sie in jeder anderen Aktivität zu laden. Das Gute an dieser Methode ist, dass sie keine Admob- oder Adsense-Richtlinien verletzt.

Verwandte Themen