// Initialize the Mobile Ads SDK. MobileAds.initialize(this, "ca-app-pub-3940256099942544~3347511713");
// Create the InterstitialAd and set the adUnitId. interstitialAd = new InterstitialAd(this); // Defined in res/values/strings.xml interstitialAd.setAdUnitId(getString(R.string.ad_unit_id));
// 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(); }
private void startGame() { // Request a new ad if one isn't already loaded, hide the button, and kick off the timer. if (!interstitialAd.isLoading() && !interstitialAd.isLoaded()) { AdRequest adRequest = new AdRequest.Builder().build(); interstitialAd.loadAd(adRequest); }
private void showInterstitial() { // Show the ad if it's ready. Otherwise toast and restart the game. if (interstitialAd != null && interstitialAd.isLoaded()) { interstitialAd.show(); } else { Toast.makeText(this, "Ad did not load", Toast.LENGTH_SHORT).show(); startGame(); } }
RewardedVideoAd mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(this); mRewardedVideoAd.setRewardedVideoAdListener(this); mRewardedVideoAd.loadAd("ca-app-pub-6391307239504132/8306864775", new AdRequest.Builder().build());
AdLoader adLoader = new AdLoader.Builder(this, "ca-app-pub-3940256099942544/2247696110") .forAppInstallAd(new NativeAppInstallAd.OnAppInstallAdLoadedListener() { @Override public void onAppInstallAdLoaded(NativeAppInstallAd appInstallAd) { // Show the app install ad. } }) .forContentAd(new NativeContentAd.OnContentAdLoadedListener() { @Override public void onContentAdLoaded(NativeContentAd contentAd) { // Show the content ad. } }) .withAdListener(new AdListener() { @Override public void onAdFailedToLoad(int errorCode) { // Handle the failure by logging, altering the UI, and so on. } }) .withNativeAdOptions(new NativeAdOptions.Builder() // Methods in the NativeAdOptions.Builder class can be // used here to specify individual options settings. .build()) .build();
private void displayAppInstallAd(ViewGroup parent,NativeAppInstallAd ad) { // Inflate a layout and add it to the parent ViewGroup. LayoutInflater inflater = (LayoutInflater) parent.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); NativeAppInstallAdView adView = (NativeAppInstallAdView) inflater .inflate(R.layout.my_ad_layout, parent);
// Locate the view that will hold the headline, set its text, and call the // NativeAppInstallAdView's setHeadlineView method to register it. TextView headlineView = adView.findViewById(R.id.ad_headline); headlineView.setText(ad.getHeadline()); adView.setHeadlineView(headlineView);
// Repeat the above process for the other assets in the NativeAppInstallAd
// If the app is using a MediaView to display video, it should be // instantiated and passed to setMediaView. This view is a little different // in that the asset is populated automatically, so there's one less step. MediaView mediaView = (MediaView) adView.findViewById(R.id.ad_media); adView.setMediaView(mediaView);
// Call the NativeAppInstallAdView's setNativeAd method to register the // NativeAdObject. adView.setNativeAd(ad);
// Place the AdView into the parent. parent.addView(adView); }
on failed for task ':childgit:app:processDebugGoogleServices'. > File google-services.json is missing. The Google Services Plugin cannot function without it. Searched Location: F:\src\git_project\qq_qqrobot\childgit\app\src\nullnull\debug\google-services.json F:\src\git_project\qq_qqrobot\childgit\app\src\debug\nullnull\google-services.json F:\src\git_project\qq_qqrobot\childgit\app\src\null
1
All firebase libraries must be either above or below 14.0.0
public final class AdRequest { public static final int ERROR_CODE_INTERNAL_ERROR = 0; public static final int ERROR_CODE_INVALID_REQUEST = 1; public static final int ERROR_CODE_NETWORK_ERROR = 2; public static final int ERROR_CODE_NO_FILL = 3;
pulic static final int ERROR_CODE_INTERNAL_ERROR = 0; public static final int ERROR_CODE_INVALID_REQUEST = 1; public static final int ERROR_CODE_NETWORK_ERROR = 2; public static final int ERROR_CODE_NO_FILL = 3;