2016-06-30 17 views
0

私はad-mobインタースティシャル広告とバナー広告を追加したいウェブビューアンドロイドアプリを作成しています。既にそのコードを実装しています。ウェブビューアプリで同じコードを試してみると、インタースティシャル広告のみが動作します。誰かが正しいコードで私を助けてくれますか?以下のコードはWebviewアプリがadmobバナー広告を表示していない

build.gradle

compile 'com.google.android.gms:play-services-ads:9.2.0' 

activity_main.xml

<WebView 
    android:id="@+id/activity_main_webview" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:visibility="gone"/> 


    <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="@string/banner_ad_unit_id"> 
</com.google.android.gms.ads.AdView> 

MainActivity.java

InterstitialAd mInterstitialAd; 
private InterstitialAd interstitial; 



AdView mAdView = (AdView) findViewById(R.id.adView); 
AdRequest adRequest = new AdRequest.Builder().build(); 
mAdView.loadAd(adRequest); 

// Prepare the Interstitial Ad 
interstitial = new InterstitialAd(MainActivity.this); 
// Insert the Ad Unit ID 
interstitial.setAdUnitId(getString(R.string.admob_interstitial_id)); 

interstitial.loadAd(adRequest); 
// Prepare an Interstitial Ad Listener 
interstitial.setAdListener(new AdListener() { 
    public void onAdLoaded() { 
     // Call displayInterstitial() function 
     displayInterstitial(); 
    } 
}); 

public void displayInterstitial() { 
// If Ads are loaded, show Interstitial else show nothing. 
if (interstitial.isLoaded()) { 
interstitial.show(); 
} 
} 

のstrings.xml

<string name="banner_ad_unit_id">ca-app-pub-3940256099942544/6300978111</string> 
<string name="admob_interstitial_id">ca-app-pub-3940256099942544/1033173712</string> 
あります3210
+0

作業このコードを試してくださいあなたのレイアウトファイルを投稿webview.iのwebviewは重複していると思うバナービュー –

+0

@MohitMadaan

+0

私が編集し、ウェブを追加しましたメインの質問でもレイアウトを見ることができます。 –

答えて

1

は、そのが

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
xmlns:ads="http://schemas.android.com/apk/res-auto" 
> 
<WebView 
    android:id="@+id/webView1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    /> 
<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="@string/banner_ad_unit_id"> 
</com.google.android.gms.ads.AdView> 

とJavaファイルに

WebView webView = (WebView) findViewById(R.id.webView1); 
    webView.getSettings().setJavaScriptEnabled(true); 
    webView.loadUrl(Url); 
    AdView mAdView = (AdView) findViewById(R.id.adView); 
    AdRequest adRequest = new AdRequest.Builder().build(); 
    mAdView.loadAd(adRequest); 
+0

それは完璧に動作しています、どうもありがとうございます。 –

0

あなたのルートビューとしてCoordinatorLayoutを使用してみてください:

<android.support.design.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" 
    android:fitsSystemWindows="true" 
    tools:context=""> 


    // yout stuff here... 

</android.support.design.widget.CoordinatorLayout> 
+0

アプリが強制終了しているので、動作していません。 –

関連する問題