com.google.android.gms.ads.initialization.OnInitializationCompleteListener Java Examples

The following examples show how to use com.google.android.gms.ads.initialization.OnInitializationCompleteListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MainActivity.java    From android-ads with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Initialize the Mobile Ads SDK.
    MobileAds.initialize(this, new OnInitializationCompleteListener() {
        @Override
        public void onInitializationComplete(InitializationStatus initializationStatus) {}
    });

    refresh = findViewById(R.id.btn_refresh);
    startVideoAdsMuted = findViewById(R.id.cb_start_muted);
    videoStatus = findViewById(R.id.tv_video_status);

    refresh.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View unusedView) {
            refreshAd();
        }
    });

    refreshAd();
}
 
Example #2
Source File: MyActivity.java    From android-ads with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my);

    // Initialize the Mobile Ads SDK.
    MobileAds.initialize(this, new OnInitializationCompleteListener() {
        @Override
        public void onInitializationComplete(InitializationStatus initializationStatus) {}
    });

    // Gets the ad view defined in layout/ad_fragment.xml with ad unit ID set in
    // values/strings.xml.
    adView = findViewById(R.id.ad_view);

    // Create an ad request. Check your logcat output for the hashed device ID to
    // get test ads on a physical device. e.g.
    // "Use AdRequest.Builder.addTestDevice("ABCDEF012345") to get test ads on this device."
    AdRequest adRequest = new AdRequest.Builder()
            .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            .build();

    // Start loading the ad in the background.
    adView.loadAd(adRequest);
}
 
Example #3
Source File: MainActivity.java    From googleads-mobile-android-examples with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Initialize the Mobile Ads SDK.
    MobileAds.initialize(this, new OnInitializationCompleteListener() {
        @Override
        public void onInitializationComplete(InitializationStatus initializationStatus) {}
    });

    refresh = findViewById(R.id.btn_refresh);
    startVideoAdsMuted = findViewById(R.id.cb_start_muted);
    videoStatus = findViewById(R.id.tv_video_status);

    refresh.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View unusedView) {
            refreshAd();
        }
    });

    refreshAd();
}
 
Example #4
Source File: GoogleAdActivity.java    From FastLib with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_google_ad);

    // Initialize the Mobile Ads SDK.
    MobileAds.initialize(this, new OnInitializationCompleteListener() {
        @Override
        public void onInitializationComplete(InitializationStatus initializationStatus) {
        }
    });

    // Create the InterstitialAd and set the adUnitId.
    interstitialAd = new InterstitialAd(this);
    // Defined in res/values/strings.xml
    interstitialAd.setAdUnitId(AD_UNIT_ID);

    interstitialAd.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
            ToastUtil.show("onAdLoaded()");
        }

        @Override
        public void onAdFailedToLoad(int errorCode) {
            ToastUtil.show("onAdFailedToLoad() with error code: " + errorCode);
        }

        @Override
        public void onAdClosed() {
            startGame();
        }
    });

    // Create the "retry" button, which tries to show an interstitial between game plays.
    retryButton = findViewById(R.id.retry_button);
    retryButton.setVisibility(View.INVISIBLE);
    retryButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            showInterstitial();
        }
    });

    startGame();
}
 
Example #5
Source File: MyActivity.java    From googleads-mobile-android-examples with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_my);

  // Initialize the Mobile Ads SDK.
  MobileAds.initialize(this, new OnInitializationCompleteListener() {
    @Override
    public void onInitializationComplete(InitializationStatus initializationStatus) {}
  });

  // Set your test devices. Check your logcat output for the hashed device ID to
  // get test ads on a physical device. e.g.
  // "Use RequestConfiguration.Builder().setTestDeviceIds(Arrays.asList("ABCDEF012345"))
  // to get test ads on this device."
  MobileAds.setRequestConfiguration(
      new RequestConfiguration.Builder().setTestDeviceIds(Arrays.asList("ABCDEF012345")).build());

  adContainerView = findViewById(R.id.ad_view_container);

  // Since we're loading the banner based on the adContainerView size, we need to wait until this
  // view is laid out before we can get the width.
  adContainerView.post(new Runnable() {
    @Override
    public void run() {
     loadBanner();
    }
  });
}
 
Example #6
Source File: MyActivity.java    From googleads-mobile-android-examples with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my);

    // Initialize the Mobile Ads SDK.
    MobileAds.initialize(this, new OnInitializationCompleteListener() {
        @Override
        public void onInitializationComplete(InitializationStatus initializationStatus) {}
    });

    // Create the InterstitialAd and set the adUnitId.
    interstitialAd = new InterstitialAd(this);
    // Defined in res/values/strings.xml
    interstitialAd.setAdUnitId(AD_UNIT_ID);

    interstitialAd.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
            Toast.makeText(MyActivity.this, "onAdLoaded()", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onAdFailedToLoad(int errorCode) {
            Toast.makeText(MyActivity.this,
                    "onAdFailedToLoad() with error code: " + errorCode,
                    Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onAdClosed() {
            startGame();
        }
    });

    // Create the "retry" button, which tries to show an interstitial between game plays.
    retryButton = findViewById(R.id.retry_button);
    retryButton.setVisibility(View.INVISIBLE);
    retryButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            showInterstitial();
        }
    });

    startGame();
}
 
Example #7
Source File: MyActivity.java    From googleads-mobile-android-examples with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my);

    // Initialize the Mobile Ads SDK.
    MobileAds.initialize(this, new OnInitializationCompleteListener() {
        @Override
        public void onInitializationComplete(InitializationStatus initializationStatus) {}
    });

    // Set your test devices. Check your logcat output for the hashed device ID to
    // get test ads on a physical device. e.g.
    // "Use RequestConfiguration.Builder().setTestDeviceIds(Arrays.asList("ABCDEF012345"))
    // to get test ads on this device."
    MobileAds.setRequestConfiguration(
        new RequestConfiguration.Builder().setTestDeviceIds(Arrays.asList("ABCDEF012345"))
                                          .build());

    // Gets the ad view defined in layout/ad_fragment.xml with ad unit ID set in
    // values/strings.xml.
    adView = findViewById(R.id.ad_view);

    // Create an ad request.
    AdRequest adRequest = new AdRequest.Builder().build();

    // Start loading the ad in the background.
    adView.loadAd(adRequest);
}
 
Example #8
Source File: MyActivity.java    From android-ads with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my);

    // Initialize the Mobile Ads SDK.
    MobileAds.initialize(this, new OnInitializationCompleteListener() {
        @Override
        public void onInitializationComplete(InitializationStatus initializationStatus) {}
    });

    // Create the InterstitialAd and set the adUnitId.
    interstitialAd = new InterstitialAd(this);
    // Defined in res/values/strings.xml
    interstitialAd.setAdUnitId(AD_UNIT_ID);

    interstitialAd.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
            Toast.makeText(MyActivity.this, "onAdLoaded()", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onAdFailedToLoad(int errorCode) {
            Toast.makeText(MyActivity.this,
                    "onAdFailedToLoad() with error code: " + errorCode,
                    Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onAdClosed() {
            startGame();
        }
    });

    // Create the "retry" button, which tries to show an interstitial between game plays.
    retryButton = findViewById(R.id.retry_button);
    retryButton.setVisibility(View.INVISIBLE);
    retryButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            showInterstitial();
        }
    });

    startGame();
}