Search code examples
javaandroidadmobgoogle-play-servicesgoogle-play-games

Ads is not visible. Not refreshing add. Scheduling ad refresh 60000 miliseconds from now


Hi i integrated an admob banner in my game via xml but it not showing in the bottom of my screen the layout of banner already appear in graphical layout .. Also when i check my logCat i saw this message "Ad is not visible. Not refreshing ad."

I used this code on my name combiner website.

this is my code java

public class FlyingPanda extends Activity{
/** Called when the activity is first created. */

public static FlyingPanda app;

public static CCGLSurfaceView mGLSurfaceView;
private boolean isCreated = false; 

private static final String AD_INTERSTITIAL_UNIT_ID = "df2cce209f194168";

/** The interstitial ad. */
private InterstitialAd interstitialAd;
private AdView adView = null;


@Override
public void onCreate(Bundle savedInstanceState) {
    if( !isCreated ){
        isCreated = true;
    } else {
        return;
    }
    
    app = this;
    
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    super.onCreate(savedInstanceState);
    
    //my code
    setContentView(R.layout.adview);
    //my code

    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    
    //my code

    AdView mAdView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);
    //my code

    RelativeLayout layout = new RelativeLayout(this);
    layout.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    
    mGLSurfaceView = new CCGLSurfaceView(this);
    
    
    
    layout.addView(mGLSurfaceView);
    
    setContentView(layout);
    
    
    
    // Create an ad request. Check logcat output for the hashed device ID to
    // get test ads on a physical device.
        //AdRequest adRequest = new AdRequest.Builder().build();
        //adView.loadAd(adRequest);
        

    //-----------------------------------------------------Interstitial Add
    // Create an Interstitial ad.
    interstitialAd = new InterstitialAd(this);
    interstitialAd.setAdUnitId(AD_INTERSTITIAL_UNIT_ID);
     // Load the interstitial ad.
    AdRequest interstitialAdRequest = new AdRequest.Builder().build();
    interstitialAd.loadAd(interstitialAdRequest);
    
    /////////////////////////////////////////////////////////////////////////////
    Common.game_initialize();
    getScaledCoordinate();
    CCDirector.sharedDirector().attachInView(mGLSurfaceView); 

    // attach the OpenGL view to a window
    Common.sound_engine = SoundEngine.sharedEngine();
    loadSound();

    CCScene scene = CCScene.node();
    scene.addChild(new HelloWorldLayer(), 1);
    CCDirector.sharedDirector().runWithScene(scene);
}

@Override
public void onStart() {
    super.onStart();
}

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

    MediaGlobal._shared().pauseMusic();

    if(GameLayer.sharedGameLayer() != null){
        GameLayer.sharedGameLayer().onPause(null);
    }
    CCDirector.sharedDirector().pause();
}

@Override
public void onResume() {
    super.onResume();

    if (adView != null) {
        adView.resume();
      }
    
    MediaGlobal._shared().resumeMusic();
}

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

    MediaGlobal._shared().stopMusic();
    Common.sound_engine.realesAllEffects();

    super.onDestroy();
    CCDirector.sharedDirector().end();       

    CCTextureCache.sharedTextureCache().removeAllTextures();
    CCTextureCache.sharedTextureCache().removeAllTextures();
    CCSpriteFrameCache.sharedSpriteFrameCache().removeAllSpriteFrames();
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if(keyCode == KeyEvent.KEYCODE_BACK){
        exitGameDialog();
        return false;
    }
    return super.onKeyDown(keyCode, event);
}

public void exitGameDialog() {
    Builder builder = new AlertDialog.Builder(FlyingPanda.this)
            .setIcon(R.drawable.icon)
            .setTitle("Quitter le jeu?")
            .setMessage("Est-vous sûr?")
            .setNegativeButton("Non", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int whichButton) {
                }
            })
            .setPositiveButton("Oui",
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog,
                                int whichButton) {
                            CCActionManager.sharedManager()
                                    .removeAllActions();
                            CCDirector.sharedDirector().end();
                            finish();
                        }
                    });
    builder.create().show();
}

private void loadSound() {
    SoundEngine.purgeSharedEngine();

    Common.sound_engine.preloadEffect(CCDirector.sharedDirector().getActivity().getApplication(), R.raw.bomb);
    Common.sound_engine.preloadEffect(CCDirector.sharedDirector().getActivity().getApplication(), R.raw.bounce);
    Common.sound_engine.preloadEffect(CCDirector.sharedDirector().getActivity().getApplication(), R.raw.death);
    Common.sound_engine.preloadEffect(CCDirector.sharedDirector().getActivity().getApplication(), R.raw.fly);
    Common.sound_engine.preloadEffect(CCDirector.sharedDirector().getActivity().getApplication(), R.raw.gamebg);
    Common.sound_engine.preloadEffect(CCDirector.sharedDirector().getActivity().getApplication(), R.raw.gameover);
    Common.sound_engine.preloadEffect(CCDirector.sharedDirector().getActivity().getApplication(), R.raw.jumppad);
}

private void getScaledCoordinate() {
    DisplayMetrics displayMetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);

    Common.SCREEN_WIDTH = displayMetrics.widthPixels;
    Common.SCREEN_HEIGHT = displayMetrics.heightPixels;
    Common.kXForIPhone = Common.SCREEN_WIDTH / 480.0f;
    Common.kYForIPhone = Common.SCREEN_HEIGHT / 320.0f;
}


// Admob Setting
////////////////////////////////////////////////////////////////////////////////

public void setHideAdView(final boolean bHide) {
    runOnUiThread(new Runnable() {
        public void run() {
            if(bHide) {
                adView.setVisibility(View.INVISIBLE);
            }
            else {
                adView.setVisibility(View.VISIBLE);
            }
        }
    });
    
    
}

public void showInterstitialAds()
{
    runOnUiThread(new Runnable() {
        public void run() {

            // Load the interstitial ad.
            AdRequest interstitialAdRequest = new AdRequest.Builder().build();
            interstitialAd.loadAd(interstitialAdRequest);
            
            interstitialAd.show();
        }
    });
}

}

and this is my xml code

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent" 
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp"
android:paddingBottom="0dp"
tools:context="com.ideanetstudio.IncroyableAventuresAlaadin.FlayingPanda">


<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="ca-app-pub-848493934849303/736373839303">
</com.google.android.gms.ads.AdView>

Solution

  • add adView.pause(); in onPause() and adView.resume(); in onResume() method:

    @Override
    protected void onPause() {
        adView.pause();
        super.onPause();
    }
    
    
    
    @Override
    protected void onResume() {
        super.onResume();
        adView.resume();
    }