我用buildbox创建了一个应用程序,并使用android studio生成了apk,但横幅未显示:/ (NB:正在显示插页式广告。) 我几乎在youtube上看到了所有的视频,但都是徒劳的..:/
布局
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/main"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingBottom="16dp"
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:orientation="vertical"
android:layout_width="353dp"
android:layout_height="match_parent"
android:weightSum="1">
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="334dp"
android:layout_height="0dp"
android:layout_weight="0.63"
ads:adSize="BANNER"
ads:adUnitId="@string/admob_id" >
</com.google.android.gms.ads.AdView>
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/madView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
</com.google.android.gms.ads.AdView>
</LinearLayout>
</FrameLayout>
Buildbox正在使用Brings,这是PTAdAdMobBridge:
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.google.android.gms.ads.*;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.vision.Frame;
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 AdView madView;
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();
PTAdAdMobBridge.showBannerAd();
}
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 = new AdRequest.Builder().setRequestAgent("android_studio:ad_template").build();
PTAdAdMobBridge.adView.loadAd( adRequest );
}
});
}
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 );
}
});
}
}
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;
}
}
这是我的“ Mainactivity.java”(注:这是PTPlayer.java)
import org.cocos2dx.lib.Cocos2dxActivity;
import org.cocos2dx.lib.Cocos2dxGLSurfaceView;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.WindowManager;
import android.widget.Toast;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.MobileAds;
import com.secrethq.store.PTStoreBridge;
import com.google.android.gms.games.GamesActivityResultCodes;
import com.secrethq.ads.*;
import com.secrethq.utils.*;
public class PTPlayer extends Cocos2dxActivity {
private static native void loadModelController();
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(){
PTAdAdMobBridge.initBridge( this );
if (PTJniHelper.isAdNetworkActive("kChartboost")) {
PTAdChartboostBridge.initBridge(this);
}
if (PTJniHelper.isAdNetworkActive("kRevMob")) {
PTAdRevMobBridge.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();
if (PTJniHelper.isAdNetworkActive("kChartboost")) {
PTAdChartboostBridge.onResume( this );
}
}
@Override
protected void onStart() {
super.onStart();
if (PTJniHelper.isAdNetworkActive("kChartboost")) {
PTAdChartboostBridge.onStart( this );
}
}
@Override
protected void onStop() {
super.onStop();
if (PTJniHelper.isAdNetworkActive("kChartboost")) {
PTAdChartboostBridge.onStop( this );
}
}
@Override
protected void onDestroy() {
super.onDestroy();
}
}
字符串:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Art of conquest Cheat Free</string>
<string name="app_id">ca-app-pub-4470388940486994~9450386360</string>
<string name="admob_id">ca-app-pub-3940256099942544/6300978111</string>
<string name="bannerId">ca-app-pub-3940256099942544/6300978111</string>
</resources>
请帮助我,我迷路了。 谢谢大家:)