ADMOB banner qui ne marche pas!
Bonjour les gars, c'est ma première discussion au forum, j'espère qu'on m'aidera à résoudre mon problème (je tiens à préciser que je suis un peu novice dans le domaine :p)
Donc mon problème, c'est que j'ai essayé de créer une petite application avec buildbox, et j'ai mis l'interstitiel, et un banner (admob) qui doit se voir dans toutes les pages de l'appli
mais je test mon appli sur android studio, l'intertitiel sort, mais le banner jamais.. voici mon PTAadmobBridge :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
| 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;
}
} |
Voila mon "mainactivity" :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
| 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();
}
} |
et le layout :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| <?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> |
une petite aide est très appréciable :)
Merci a vous !