The Admob platform is displaying test ads, but my actual ads are not appearing

I'm currently using Admob to display Android ads in my app. Strangely, my actual ads are not appearing, but when I input the test code, it works perfectly fine. Interestingly, when I tested my ads in a different game, they displayed as intended. It's worth mentioning that this game was created using buildbox.

private static AdRequest getAdRequest(){
    // 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()
            // uncomment to get test ads
            //.addTestDevice("YOUR_DEVICE_ID")
            .build();
    return adRequest;

Answer №1

import com.secrethq.ads;

import java.lang.ref.WeakReference;

import org.cocos2dx.lib.Cocos2dxActivity;

import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

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

public class PTAdAdMobBridge {
    private static final String TAG = "PTAdAdMobBridge";
    private static Cocos2dxActivity activity;
    private static WeakReference<Cocos2dxActivity> s_activity;
    private static AdView adView;
    private static InterstitialAd interstitial;
    private static LinearLayout layout;

    private static native String bannerId();
    private static native String interstitialId();
    private static native void interstitialDidFail();
    private static native void bannerDidFail();

    private static boolean isBannerScheduledForShow = false;
    private static boolean isInterstitialScheduledForShow = false;

    public static void initBridge(Cocos2dxActivity activity){
        Log.v(TAG, "PTAdAdMobBridge  -- INIT");


        PTAdAdMobBridge.s_activity = new WeakReference<Cocos2dxActivity>(activity); 
        PTAdAdMobBridge.activity = activity;

        MobileAds.initialize(PTAdAdMobBridge.activity, PTAdAdMobBridge.bannerId());

        PTAdAdMobBridge.initBanner();
        PTAdAdMobBridge.initInterstitial();

    }

    public static void initBanner(){
        Log.v(TAG, "PTAdAdMobBridge  -- initBanner");
        PTAdAdMobBridge.s_activity.get().runOnUiThread( new Runnable() {
            public void run() {

                if(PTAdAdMobBridge.adView != null){
                    return;
                }

                FrameLayout frameLayout = (FrameLayout)PTAdAdMobBridge.activity.findViewById(android.R.id.content);
                RelativeLayout layout = new RelativeLayout( PTAdAdMobBridge.activity );
                frameLayout.addView( layout );

                RelativeLayout.LayoutParams adViewParams = new RelativeLayout.LayoutParams(
                        AdView.LayoutParams.WRAP_CONTENT,
                        AdView.LayoutParams.WRAP_CONTENT);
                adViewParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
                adViewParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);

                PTAdAdMobBridge.adView = new AdView( PTAdAdMobBridge.activity );
                PTAdAdMobBridge.adView.setAdSize(AdSize.SMART_BANNER);
                PTAdAdMobBridge.adView.setAdUnitId( PTAdAdMobBridge.bannerId() );

                layout.addView(PTAdAdMobBridge.adView, adViewParams);
                PTAdAdMobBridge.adView.setVisibility( View.INVISIBLE );

                AdRequest adRequest = getAdRequest();
                PTAdAdMobBridge.adView.loadAd( adRequest );     
            }
        });

    }

    public static boolean isBannerVisible(){
        if(PTAdAdMobBridge.adView == null){
            return false;
        }
        else{
            if(PTAdAdMobBridge.adView.getVisibility() == View.VISIBLE){
                return true;
            }
            else{
                return false;
            }
        }
    }

    public static void initInterstitial(){
        Log.v(TAG, "PTAdAdMobBridge  -- initInterstitial");
        PTAdAdMobBridge.s_activity.get().runOnUiThread( new Runnable() {
            public void run() {

                if(PTAdAdMobBridge.interstitial != null){
                    return;
                }

                AdRequest adRequest = getAdRequest();

                PTAdAdMobBridge.interstitial = new InterstitialAd( PTAdAdMobBridge.activity );
                PTAdAdMobBridge.interstitial.setAdUnitId( PTAdAdMobBridge.interstitialId() );
                PTAdAdMobBridge.interstitial.setAdListener(new AdListener() {
                    @Override
                    public void onAdLoaded() {
                        if(PTAdAdMobBridge.isInterstitialScheduledForShow){
                            PTAdAdMobBridge.showFullScreen();
                        }
                    }

                    @Override
                    public void onAdClosed() {
                        AdRequest adRequest = new AdRequest.Builder().build();
                        PTAdAdMobBridge.interstitial.loadAd(adRequest);
                    }

                    @Override
                    public void onAdFailedToLoad(int errorCode) {
                        if ( !isInterstitialScheduledForShow )
                            return;

                        PTAdAdMobBridge.interstitialDidFail();
                    }
                });

                PTAdAdMobBridge.interstitial.loadAd(adRequest);
            }
        });
    }



    public static void showFullScreen(){
        Log.v(TAG, "showFullScreen");

        isInterstitialScheduledForShow = true;

        if(PTAdAdMobBridge.interstitial != null){
            PTAdAdMobBridge.s_activity.get().runOnUiThread( new Runnable() {
                public void run() {
                    if(PTAdAdMobBridge.interstitial.isLoaded()){
                        PTAdAdMobBridge.interstitial.show();
                        PTAdAdMobBridge.isInterstitialScheduledForShow = false;
                    }
                    else{
                        PTAdAdMobBridge.isInterstitialScheduledForShow = true;
                    }
                }
            });
        }
    }



    public static void showBannerAd(){
        Log.v(TAG, "showBannerAd");

        isBannerScheduledForShow = true;

        if(PTAdAdMobBridge.adView != null){
            PTAdAdMobBridge.s_activity.get().runOnUiThread( new Runnable() {
                public void run() {
                    AdRequest adRequest = getAdRequest();

                    PTAdAdMobBridge.adView.loadAd(adRequest);
                    PTAdAdMobBridge.adView.setAdListener(new AdListener() {                 
                        @Override
                        public void onAdFailedToLoad(int errorCode) {
                            if ( !isBannerScheduledForShow )
                                return;

                            Log.v(TAG, "Banner Ad Failed To Load");
                            PTAdAdMobBridge.bannerDidFail();
                        }

                        @Override
                        public void onAdLoaded() {
                            Log.v(TAG, "Banner Ad Loaded");
                            PTAdAdMobBridge.adView.setVisibility( isBannerScheduledForShow ? View.VISIBLE : View.INVISIBLE );
                        }
                    });
                    PTAdAdMobBridge.adView.setVisibility( View.VISIBLE );
                }
            });         
        }



    }

    public static void hideBannerAd(){
        Log.v(TAG, "hideBannerAd");

        isBannerScheduledForShow = false;

        if(PTAdAdMobBridge.adView != null){
            PTAdAdMobBridge.s_activity.get().runOnUiThread( new Runnable() {
                public void run() {
                    PTAdAdMobBridge.adView.setVisibility( View.INVISIBLE );
                }
            });
        }
    }

    private static AdRequest getAdRequest(){
        // 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()
                // uncomment to get test ads
                //.addTestDevice("YOUR_DEVICE_ID")
                .build();
        return adRequest;
    }

}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issues with JavaScript Content Loading in epub.js on a Website

Hey there, I'm currently experimenting with the epub.js library and trying to set up the basics. However, I'm encountering an issue where the ebook is not showing up in my browser: <!DOCTYPE html> <html lang="en"> <head&g ...

When using Firestore in Android, I encounter a nodejs error regarding headers being sent prematurely

Currently, I am utilizing a webview in order to display content from a nodejs server. While requesting a page works as expected, accessing firestore results in an error where it seems like nodejs is attempting to resend the page. Below is the code for an a ...

"Utilizing AngularJS event system through $broadcast and $on

I have recently started learning AngularJS and I am trying to send a message from one controller to another. I have looked at various examples and my code seems to be similar, but it is not working. Why is $rootScope.$on not working? Can anyone help me wit ...

Tips for fixing the error message "java.net.ConnectException: unable to establish connection to /10.0.2.2 (port 8080): connection failed: ETIMEDOUT (Connection timed out)"

I have been working on an application that is designed to upload files from the SD card to a PHP server for further processing. However, when attempting to upload, I encountered the following error in my logcat: java.net.ConnectException: failed to connect ...

Why is the axios.get promise not getting resolved?

I am currently working on fetching data from MongoDB atlas within a React app. However, despite using .then and .catch with axios.get(), I am encountering an unresolved promise. Here is the code snippet: const entry = axios.get('http://localhost:3001 ...

Is it possible to create a jQuery animation that toggles from top to bottom with a 'slow' speed setting?

I recently implemented a hidden div appearing/disappearing animation in my code using jQuery's toggle('slow'). The current effect makes the div expand from the upper left corner to the bottom right corner. Is there a way to modify the anima ...

Embed a script into an iframe from a separate domain

While experimenting, I attempted to inject a script inside an iframe element using the following method. However, since the child and parent elements do not belong to the same domain (and I am aware that XSS is prevented in modern browsers), I was wonder ...

Limiting the quantity in SimpleCart (js)

Currently, I am working on a WordPress website where I am using simpleCart(js) to add a shopping cart feature. I sell unique articles and do not require users to add more than one article to their cart. My main concern is how to prevent users from adding ...

Unexpected behavior encountered with JQueryUI modal functionality

Today marks my first experience with JqueryUI. I am attempting to display a conditional modal to notify the user. Within my ajax call, I have this code snippet: .done(function (result) { $('#reportData').append(result); ...

Having trouble loading SVG component in Next.js with SVGR integration

I recently obtained an SVG react component that was automatically converted from the SVGR playground page. I integrated it into my project and followed the installation instructions for @svgr/webpack and configured the setup as advised. However, upon loadi ...

Loading a three.js model with OBJMTLLoader and spinning it around

After successfully using the OBJMTLLoader class for one obj file and achieving proper rotation around a fixed point on the object with object.rotation.y -= 0.5, I encountered an unexpected issue when trying to replicate the same code with a different .obj ...

Is there a way to combine an onclick function with a return false statement within a submit button?

As far as I know, the default behavior when using return false is: <input type="submit" onclick="return false" /> However, in my current code, I want a submit button to trigger a different JavaScript function on click. This funct ...

Once I incorporated Bootstrap into my project, I noticed a noticeable white space between the div elements

Welcome to My Code Playground I was sailing smoothly with my project until I decided to include Bootstrap. Seems like there's something missing in the details, so here I am reaching out. If you spot the issue, please feel free to correct my code. &l ...

WebVTT captions on a Chromecast receiver as the default option

Trying to set up closed captions for chromecast using the default Chrome sender app but it's not working. The code is similar to the sample provided in the docs, seen here. I've shared a snippet that might be too sandboxed, view it on a normal ht ...

Customer is unable to locate the "InitializeAuthenticationService" function

After launching my application, the browser console keeps showing me three errors that all say Could not find 'AuthenticationService.init' ('AuthenticationService' was undefined). and Microsoft.JSInterop.JSException: Could not find &apo ...

JavaScript code that formats input prices, detects any formatting errors

Before jumping to conclusions, I want to clarify that I am not inquiring about the actual process of formatting the price. Instead, I am seeking guidance on where I may be going wrong or what steps I need to take in order to achieve the desired outcome. I ...

Is there a way to extract an icon from an object or array?

Currently, I am facing challenges in extracting an icon from either an object or an array for a project I am working on. My approach involves storing the icon in a variable and passing it as a prop to another component. However, the functionality is not wo ...

Steps to modify the border width upon gaining focus

I am struggling to adjust the border width when my input box is focused. Currently, it has a 1px solid border which changes to a 2px different color solid border upon focus. However, this change in border width is causing the containing div to shift by 1px ...

Customizing button appearances in the control div on Google Maps - A guide

Is there a way to manipulate elements and adjust styles by clicking buttons on the map control div? I want to achieve the same effect on the map as with the buttons in the table. Code: jsFiddle Update: Thanks to your assistance, I was able to achieve th ...

pressing a button unrelated to the 'close' button still triggers the close event

I have a notification bar that features a button in the center that links to another website. There is also a 'close' button on the far right. However, whenever I click the center button, it also triggers the close button. I tried moving the #cl ...