AdRequest () constructor not showing

I am trying to place some kind of ad in my Android app, but I have a problem ...

package com.dotgears.flappybird;
import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;

import com.google.ads.*;


public class BannerSample extends Activity {
      private AdView adView;

      @Override
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Create the adView
        adView = new AdView(this, AdSize.BANNER, "...");

        // Lookup your LinearLayout assuming it been given
        // the attribute android:id="@+id/mainLayout"
        LinearLayout layout = (LinearLayout)findViewById(R.id.linearLayout);

        // Add the adView to it
        layout.addView(adView);

        // Initiate a generic request to load it with an ad
        adView.loadAd(new AdRequest());
      }

      @Override
      public void onDestroy() {
        if (adView != null) {
          adView.destroy();
        }
        super.onDestroy();
      }
    }

I followed Google dev, but on the adView.loadAd(new AdRequest());Eclipse line it says:

AdRequest () constructor not showing

Why is it not visible? I searched everywhere but found nothing.

+4
source share
3 answers

Do it this way

AdRequest adreq=new AdRequest.Builder().build();
     adview.loadAd(adreq);

and it will work. also import it with

import com.google.android.gms.ads.AdRequest;

and he will start to work

+3
source

just use the following import

import com.google.android.gms.ads.AdRequest;

also add lib from google play services

+3
source

. Google Play Google Admob , Google Play, !

0
source

Source: https://habr.com/ru/post/1526037/


All Articles