QtAndroidTools: AdMobBanner


AdMobBanner allow to show AdMob banner inside QML app

QtAndroidTools is a library that allows to simplify access to some native Android features from QML



QtAndroidTools library source here. The project provide a demo app showing the use of all features.

Official documentation about AdMob banner is here, please read before continue for understand the options exported by the tool. Remember for allow banner to be loaded your app need the following permissions:

android.permission.INTERNET
android.permission.ACCESS_NETWORK_STATE
android.permission.WRITE_EXTERNAL_STORAGE

In add of this you have to install the AdMob required packages through Android SDK Manager. The packages you have to install are the following:
  • Google Repository
  • Google Play services
  • Support Repository
Than you have to add the following dependencies into your app gradle file:

dependencies {
    ....
    implementation 'com.google.android.gms:play-services-ads:16.+'
}

Banner is showed inside the following QML item:

import QtAndroidTools 1.0

QtAndroidAdMobBanner {
    id: banner
    unitId: "admob-banner-unit-id"
    type: QtAndroidAdMobBanner.TYPE_BANNER
}

The unitId is the string generated when you create a new ad unit inside the AdMob site. It's used to identify the ad connected to your app. Using this id you can know how much you earn from this ad unit. The property type is the banner type you want to show. Possible values are:

TYPE_BANNER
TYPE_FULL_BANNER
TYPE_LARGE_BANNER
TYPE_MEDIUM_RECTANGLE
TYPE_SMART_BANNER
TYPE_WIDE_SKYSCRAPER

This item generate the following signals informing regarding the ad status:

onLoadError
onLoading
onLoaded
onClosed
onClicked

The only signal passing a param is onLoadError, called in case of problem in loading ad. The param is errorId and possible values are:

ERROR_INTERNAL
ERROR_NETWORK
ERROR_INVALID_REQUEST
ERROR_NO_FILL

When you want to load and show the banner you have to call the show() function and for hide the hide() functions as follow (banner is the id name of the item in the example above):

banner.show()
banner.hide()

Please note the banner is a native android view over the QML window, that's mean will stay over anything painted into in and you can not place nothing over the banner.


 


Comments

Popular posts from this blog

Access GPIO from Linux user space

Launch an app from Android shell terminal

Android: adb push and read-only file system error