AdMob Qt 5.2 banner doesn't show on start of app
-
Hello
After a lot of searching and looking at qt examples and sources i found the way how to add admob to qt.first i have to implement activity by inhering QtActivity
second add this code:
@ private AdView mAdView;@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mAdView = new AdView(this); mAdView.setAdUnitId("your admob id"); mAdView.setAdSize(AdSize.BANNER); View view = getWindow().getDecorView().getRootView(); if (view instanceof ViewGroup) { ViewGroup viewGroup = (ViewGroup) view; ViewGroup.LayoutParams ad_layout_params = new ViewGroup.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, 200); mAdView.setLayoutParams(ad_layout_params); viewGroup.addView( mAdView); AdRequest adRequest = new AdRequest.Builder() .addTestDevice(AdRequest.DEVICE_ID_EMULATOR) .addTestDevice("INSERT_YOUR_HASHED_DEVICE_ID_HERE") .build(); mAdView.loadAd( adRequest); } } @Override public void onPause() { mAdView.pause(); super.onPause(); } @Override public void onResume() { super.onResume(); mAdView.resume(); } @Override public void onDestroy() { mAdView.destroy(); super.onDestroy(); }@
but i have two major problems
first:
admob banner is invisible at startup, and to see it i switch to other app then come back and after this magic i can see it
and if i click in area where ad should be it respond even if it is invisiblesecond
after i came back to app from other if i click on some controls in qml for example it blink with black screen
and after that all works fineSo, does anybody can help to solve first and second problems
-
I didn't play around with the Qt and Java integration yet, but I have a generation question about that.
Is the AdMob protocol published somewhere? I mean do you have to use the Java class "AdView" or can you just implement the AdMod protocol itself with Qt/QML, so you won't need any Java at all, because there might be rendering issues like flickering and stuff if you mix QML and Java UI as you mentioned. :/Edit: if you are using QML for the UI you may be able to use the JavaScript SDK for AdMod without any changes: http://media.admob.com/api/v1/docs/ since QML is based on JavaScript it can just use most javaScript libs.
Looking at the JS code it seems like it uses some DOM function that won't work in QMl obviously because there is no DOM.. but you might still have a look.I think a pure javaScript or c++/Qt solution would be better because the Java code can only be used on android platforms and is not platform independent.
-
As i can see AdMob is closed now. I searched for some c++ implementation or protocol description and no results. All i know is that v-play has admob plugin in qml. Admob integrated in google play service which is proprietary.
About using java AdView:
Yes, no platform independency but this is just little part of eny project and i can live with it until it will be implemented in qt.
About rendering issues, yes this post is written because i already faced with them, but this problem is in some part of qt implementation, and also qt uses android java classes ViewGroup, SurfaceView to draw so it is right way to use AdView -
There is page on my blog with example!
http://xanm.blogspot.ru/2014/03/admob-in-qt.html
I hope it helps to someone. -
[quote author="xanm" date="1396262942"]There is page on my blog with example!
http://xanm.blogspot.ru/2014/03/admob-in-qt.html
I hope it helps to someone.[/quote]It helps a lot, thank you!
Could be position of AdView adjusted (place it to the bottom) and make it the way it would not overlap QML view's space? Like if you add it to LinearLayout?
-
@Anatoly If you still have problems with positioning your banners you can have a look at our AdMob plugin, which supports anchoring of ad banners like you're used to it from other QML-based items, like this example:
AdMobBanner { adUnitId: "<your-adunit-id>" banner: AdMobBanner.Smart anchors.bottom: parent.bottom }
Cheers,
Alex