I am working with cocos2dx JS 3.0 and I am trying to implement Admob directly in Android without going through cocos2dx calls.
Created AdUnit and implemented the AdView as follows:
AdRequest request = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("AC2DFFFAFB44FE1EBC80F6B40559AB14")
.build();
AdView adView = new AdView(AppActivity.this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId("ca-app-pub-XYZ/XYZ");
adView.loadAd(request);
@SuppressWarnings("deprecation")
ViewGroup.LayoutParams ad_layout_params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
adView.setLayoutParams(ad_layout_params);
mFrameLayout.addView(adView); //Here `mFrameLayout` is the core `RelativeLayout` that contains GLView's that run cocos engine.
In Logcat, I am getting the following, but the AD is not displayed !!
Starting ad request.
JS: [Some JS Logs]
Ad finished loading.
Scheduling ad refresh 60000 milliseconds from now.
Ad is not visible. Not refreshing ad.
Scheduling ad refresh 60000 milliseconds from now.
Ad is not visible. Not refreshing ad.
Scheduling ad refresh 60000 milliseconds from now.
Ad is not visible. Not refreshing ad.
[repeating]
I guess, the admob Integration is done right, but issue with adding the AdView to the right parent view or issue with setting the position of AdView.
As per this thread ( Move AdView to bottom, Cocos2dx Activity ), changed the mFrameLayout
in Cocos2dxActivity
to RelativeLayout
Any help would be highly appreciated !!
Resolved the issue... :-)
The glSurfaceView
that is getting returned by onCreateView
is added to mFrameLayout
in the superclass Cocos2dxActivity
, hence taking over the adview
...
Hence,
AdView
in here, Cocos2dxActivity
,
glSurfaceView
is added to mFrameLayout
Code:
onCreateView of our Activity:
AdRequest request = new AdRequest.Builder()
.build();
AdView adView = new AdView(AppActivity.this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId("ca-app-pub-XYZ");
adView.setId(999);
adView.loadAd(request);
@SuppressWarnings("deprecation")
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
adView.setLayoutParams(params);
mFrameLayout.addView(adView);
In frameworks/js-bindings/cocos2d-x/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java:190 end of init
function,
mFrameLayout.bringChildToFront(mFrameLayout.findViewById(999));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.