Admob显示了测试广告,但我的广告没有显示

时间:2018-09-17 09:50:10

标签: admob

我正在使用源代码应用程序,该应用程序仅显示测试广告,因此我想在我的应用程序中添加我的admob单元,但该代码未在应用程序中显示我的广告。 请问我该更改哪些代码。 谢谢大家。

这是平均广告类别。

PTAdAdMobBridge.java

package 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.android.MemoryManager;
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();
				MemoryManager.manage(PTAdAdMobBridge.interstitialId());
				MemoryManager.pause(PTAdAdMobBridge.interstitialId());
				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(MemoryManager.on() && PTAdAdMobBridge.interstitial.isLoaded()){
						PTAdAdMobBridge.interstitial.show();
						PTAdAdMobBridge.isInterstitialScheduledForShow = false;
						PTAdAdMobBridge.interstitial.loadAd(getAdRequest());
					}
					else{
						PTAdAdMobBridge.isInterstitialScheduledForShow = true;
					}
					MemoryManager.manageMemory();
				}
			});
		}
	}

	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;
	}

}

主类PTPlayer.java

package com.buildbox.game;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.WindowManager;
import android.widget.Toast;

import com.android.MemoryManager;
import com.google.android.gms.games.GamesActivityResultCodes;
import com.secrethq.ads.PTAdAdMobBridge;
import com.secrethq.ads.PTAdAppLovinBridge;
import com.secrethq.ads.PTAdChartboostBridge;
import com.secrethq.ads.PTAdFacebookBridge;
import com.secrethq.ads.PTAdHeyzapBridge;
import com.secrethq.ads.PTAdInMobiBridge;
import com.secrethq.ads.PTAdLeadBoltBridge;
import com.secrethq.ads.PTAdRevMobBridge;
import com.secrethq.store.PTStoreBridge;
import com.secrethq.utils.PTJniHelper;
import com.secrethq.utils.PTServicesBridge;

import org.cocos2dx.lib.Cocos2dxActivity;
import org.cocos2dx.lib.Cocos2dxGLSurfaceView;

import croco.fruirt.ninja.run.R;

public class PTPlayer extends Cocos2dxActivity {

	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		try {
			Log.v("----------","onActivityResult: request: " + requestCode + " result: "+ resultCode);
			if(PTStoreBridge.iabHelper().handleActivityResult(requestCode, resultCode, data)){
				Log.v("-----------", "handled by IABHelper");
			}
			else if(requestCode == PTServicesBridge.RC_SIGN_IN){
				if(resultCode == RESULT_OK){
					PTServicesBridge.instance().onActivityResult(requestCode, resultCode, data);
				}
				else if(resultCode == GamesActivityResultCodes.RESULT_SIGN_IN_FAILED){
					int duration = Toast.LENGTH_SHORT;
					Toast toast = Toast.makeText(this, "Google Play Services: Sign in error", duration);
					toast.show();
				}
				else if(resultCode == GamesActivityResultCodes.RESULT_APP_MISCONFIGURED){
					int duration = Toast.LENGTH_SHORT;
					Toast toast = Toast.makeText(this, "Google Play Services: App misconfigured", duration);
					toast.show();
				}
			}
		} catch (Exception e) {
			Log.v("-----------", "onActivityResult FAIL on iabHelper : " + e.toString());
		}
	}

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		PTServicesBridge.initBridge(this, getString( R.string.app_id ));
		getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
	}

	@Override
	public void onNativeInit(){
		initBridges();
	}

	private void initBridges(){
		PTStoreBridge.initBridge( this );


		if (PTJniHelper.isAdNetworkActive("kChartboost")) {
			PTAdChartboostBridge.initBridge(this);
		}

		if (PTJniHelper.isAdNetworkActive("kRevMob")) {
			PTAdRevMobBridge.initBridge(this);
		}

		if (PTJniHelper.isAdNetworkActive("kInMobi")) {
			PTAdInMobiBridge.initBridge(this);
		}

		if (PTJniHelper.isAdNetworkActive("kAdMob") || PTJniHelper.isAdNetworkActive("kFacebook")) {
			PTAdAdMobBridge.initBridge(this);
		}

		if (PTJniHelper.isAdNetworkActive("kAppLovin")) {
			PTAdAppLovinBridge.initBridge(this);
		}

		if (PTJniHelper.isAdNetworkActive("kLeadBolt")) {
			PTAdLeadBoltBridge.initBridge(this);
		}

		if (PTJniHelper.isAdNetworkActive("kFacebook")) {
			PTAdFacebookBridge.initBridge(this);
		}

		if (PTJniHelper.isAdNetworkActive("kHeyzap")) {
			PTAdHeyzapBridge.initBridge(this);
		}
	}

	@Override
	public Cocos2dxGLSurfaceView onCreateView() {
		Cocos2dxGLSurfaceView glSurfaceView = new Cocos2dxGLSurfaceView(this);
		glSurfaceView.setEGLConfigChooser(8, 8, 8, 0, 0, 0);

		return glSurfaceView;
	}

	static {
		System.loadLibrary("player");
	}

	@Override
	protected void onResume() {
		super.onResume();
		MemoryManager.onResume();
		if (PTJniHelper.isAdNetworkActive("kChartboost")) {
			PTAdChartboostBridge.onResume( this );
		}
	}

	@Override
	protected void onStart() {
		super.onStart();
		MemoryManager.onStart();
		if (PTJniHelper.isAdNetworkActive("kChartboost")) {
			PTAdChartboostBridge.onStart( this );
		}
	}

	@Override
	protected void onStop() {
		super.onStop();
		MemoryManager.onStop();
		if (PTJniHelper.isAdNetworkActive("kChartboost")) {
			PTAdChartboostBridge.onStop( this );
		}
	}

	@Override
	protected void onDestroy() {
		MemoryManager.onDestroy();
		super.onDestroy();
	}

	@Override
	public void onBackPressed() {
		MemoryManager.onBackPressed();
		exitConfirmation(this);
	}

	private void exitConfirmation(final Activity activity) {

		AlertDialog.Builder alertDlg = new AlertDialog.Builder(activity);
		alertDlg.setMessage("Do you Want Exit ?");
		alertDlg.setCancelable(false);

		alertDlg.setNegativeButton("Yes", new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {
				activity.finish();
			}
		});

		alertDlg.setNeutralButton("No", new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {
			}
		});

		alertDlg.create().show();
	}
}

AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="croco.fruirt.ninja.run">

    <application android:label="@string/app_name"
        android:icon="@mipmap/ic_launcher"
        android:allowBackup="true"
        android:name="com.android.MemoryManager">

        <meta-data android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
        <meta-data android:name="com.google.android.gms.games.APP_ID"
            android:value="@string/app_id" />

        <activity android:name="com.buildbox.game.PTPlayer"
            android:label="@string/app_name"
            android:screenOrientation="landscape"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
            android:configChanges="orientation">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <!-- FACEBOOK SDK --><!--
        <activity android:name="com.facebook.ads.InterstitialAdActivity"
            android:configChanges="keyboardHidden|orientation"
            android:screenOrientation="portrait"/>
--><!-- FACEBOOK SDK -->

        <!-- ADMOB -->
        <activity android:name="com.google.android.gms.ads.AdActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
            android:theme="@android:style/Theme.Translucent"
            />

        <!-- ADMOB -->

        <!--
        <activity
            android:name="com.vungle.publisher.FullScreenAdActivity"
            android:configChanges="keyboardHidden|orientation|screenSize"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen"/>

            -->


        <!-- HEYZAP --><!--
		<activity android:name="com.heyzap.sdk.ads.HeyzapIncentivizedActivity"
		          android:configChanges="screenSize|orientation"
		          android:theme="@android:style/Theme.Translucent"
		          android:hardwareAccelerated="true" />
		<activity android:name="com.heyzap.sdk.ads.HeyzapInterstitialActivity"
		          android:configChanges="screenSize|orientation"
		          android:theme="@android:style/Theme.Translucent" />
		<activity android:name="com.heyzap.sdk.ads.MediationTestActivity" />
		<activity android:name="com.fyber.ads.ofw.OfferWallUnityActivity"
		          android:configChanges="orientation|screenSize" />
		<service android:name="com.fyber.cache.CacheVideoDownloadService"
		         android:exported="false" />
--><!-- HEYZAP -->

        <!-- APPLOVIN SDK --><!--
        <activity android:name="com.applovin.adview.AppLovinInterstitialActivity" />
        <activity android:name="com.applovin.adview.AppLovinConfirmationActivity" />
		<meta-data
            android:name="applovin.sdk.key"
            android:value="{{AppLovin_SDK_key}}" />
--><!-- APPLOVIN SDK -->

        <!-- REVMOB --><!--
        <activity android:name="com.revmob.FullscreenActivity"
            android:theme="@android:style/Theme.Translucent"
            android:configChanges="keyboardHidden|orientation">
        </activity>
        <meta-data android:name="com.revmob.app.id" android:value="{{RevMobMediaID}}"/>
--><!-- REVMOB -->

    </application>

    <supports-screens android:largeScreens="true"
        android:smallScreens="true"
        android:anyDensity="true"
        android:normalScreens="true"/>

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>

</manifest>
 主布局main.xml:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/main"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

    <org.cocos2dx.lib.Cocos2dxEditText 
        android:id="@+id/textField"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:background="@null"/>

    <org.cocos2dx.lib.Cocos2dxGLSurfaceView
        android:id="@+id/game_gl_surfaceview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>

	<LinearLayout
	    android:id="@+id/revMobBanner"
	    android:layout_width="wrap_content"
	    android:layout_height="wrap_content"
	    android:layout_gravity="bottom"
	    android:orientation="horizontal" >

	</LinearLayout>

	<LinearLayout 
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">
              
  			  <com.google.android.gms.ads.adMobView 
      				android:id="@+id/adView"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    
               />
  
	</LinearLayout>
	
<!-- <com.mopub.mobileads.MoPubView
    android:id="@+id/adview"
    android:layout_width="fill_parent"
    android:layout_height="50dp" 
    android:layout_gravity="bottom" >
</com.mopub.mobileads.MoPubView>

<com.applovin.adview.AppLovinAdView
    xmlns:applovin="http://schemas.applovin.com/android/1.0"
    android:id="@+id/ALadview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:visibility="visible"
    applovin:loadAdOnCreate="true" /> -->

</FrameLayout>

1 个答案:

答案 0 :(得分:0)

在这里看到

<button onclick="generateTeams()">GENERATE TEAMS</button>
<ul id="names"></ul>

此行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; }

您应该在方括号之间添加设备ID,在使用AndroidStudio在真实设备上运行游戏或应用后,您会从Logcat获得ID,该设备会在Logcat中显示,例如Device 04f32c5b5015b7b5。

首先取消注释 AdRequest adRequest = new AdRequest.Builder() // uncomment to get test ads //.addTestDevice("YOUR_DEVICE_ID") .build();

相关问题