Приложение Webview не показывает рекламные баннеры admob

Я создаю приложение для Android с веб-просмотром, в которое я хочу добавить межстраничные объявления и рекламные баннеры ad-mob, я уже реализовал для этого коды, и они отлично работают в моем тестовом приложении, но когда я пробую те же коды в своем веб- просмотр приложений работает только с межстраничными объявлениями. может кто-нибудь, пожалуйста, помогите мне с правильными кодами. Ниже приведены коды

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>

person sagar chaudhary    schedule 30.06.2016    source источник
comment
опубликуйте свой файл макета веб-просмотра. я думаю, что веб-просмотр перекрывает вид баннера   -  person Mohit Madaan    schedule 30.06.2016
comment
@MohitMadaan ‹WebView android: id = @ + id / activity_main_webview android: layout_width = match_parent android: layout_height = match_parent android: visibility = Go /›   -  person sagar chaudhary    schedule 30.06.2016
comment
Я также отредактировал и добавил макет веб-просмотра в основной вопрос.   -  person sagar chaudhary    schedule 30.06.2016


Ответы (2)


Попробуйте с этим кодом. Это работает.

<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>

and in java file

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);
person Mohit Madaan    schedule 30.06.2016

Попробуйте использовать 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>
person Itiel Maimon    schedule 30.06.2016