Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. AdMob Qt 5.2 banner doesn't show on start of app

AdMob Qt 5.2 banner doesn't show on start of app

Scheduled Pinned Locked Moved Mobile and Embedded
8 Posts 5 Posters 4.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xanm
    wrote on last edited by
    #1

    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 invisible

    second
    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 fine

    So, does anybody can help to solve first and second problems

    1 Reply Last reply
    0
    • X Offline
      X Offline
      Xander84
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • X Offline
        X Offline
        xanm
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • X Offline
          X Offline
          xanm
          wrote on last edited by
          #4

          I've found solution to show add at application start
          @ mAdView.setAdListener( new AdListener() {
          public void onAdLoaded(){
          viewGroup.addView( mAdView);
          }
          });@

          but still have blinking

          1 Reply Last reply
          0
          • X Offline
            X Offline
            xanm
            wrote on last edited by
            #5

            There is page on my blog with example!
            http://xanm.blogspot.ru/2014/03/admob-in-qt.html
            I hope it helps to someone.

            1 Reply Last reply
            0
            • H Offline
              H Offline
              habamax
              wrote on last edited by
              #6

              [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?

              1 Reply Last reply
              0
              • A Offline
                A Offline
                Anatoly
                wrote on last edited by
                #7

                Hello !
                Did anyone solve the problem of position a banner on the screen ? I would like to put a banner at the bottom of my QML app. Maybe someone could explain how to do that. Thank you.

                A 1 Reply Last reply
                0
                • A Anatoly

                  Hello !
                  Did anyone solve the problem of position a banner on the screen ? I would like to put a banner at the bottom of my QML app. Maybe someone could explain how to do that. Thank you.

                  A Offline
                  A Offline
                  alexvplay
                  wrote on last edited by
                  #8

                  @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

                  CoFounder of Felgo - https://felgo.com/qt

                  Felgo simplifies Mobile App & Game Development with Qt
                  What others say: Felgo scored #1 in Cross-Platform App Development Tools Report - see why: https://goo.gl/rgp3rq

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved