The demo application demonstrates the integration of several advertising platforms in a single application and the use of advertising banners in non-standard situations. The application emulates the process of purchasing movie tickets with the ability to choose between available cinemas.
The following advertising platforms are used:
- Leadbolt (https://www.leadbolt.com/)
- Adform (https://site.adform.com/)
- Inmobi (https://www.inmobi.com/)
-
Using with Google Maps
-
Using as an element of GridView
-
Using inside of CoordinatorLayout
-
Handling the back button as a separate event (implemented only for Leadbolt)
- To add an SDK to the project, you need to download the
.jar
file at this link. - Put the downloaded file in the
libs
folder of your application or module. - Add a dependency to the
build.gradle
file of the application / module level:implementation fileTree(dir: 'libs', include: ['*.jar']) implementation "com.google.android.gms:play-services-base:[actual_version]"
- More detailed instructions can be found on the link.
- Add to the
build.gradle
file of the project level repository:allprojects { repositories { ... maven { url "https://github.com/adform/adform-android-sdk/raw/master/releases/" } } }
- Add a dependency to the
build.gradle
file of the application / module level:implementation "com.adform.advertising.sdk:advertising-sdk:[actual_version]@aar" implementation "com.google.android.gms:play-services-ads:[actual_version]"
- More detailed instructions can be found on the link.
- Integration is described in detail in our article How to Integrate InMobi SDK to Start Monetizing Your Android App and also you can look at the official website Android Guidelines | Getting Started with Android SDK Integration
An interface AdProvider
has been created to interact with various SDK's:
interface AdProvider : LifecycleObserver {
fun init(context: Context)
fun inflateDefaultBanner(parent: ViewGroup, lifecycleOwner: LifecycleOwner)
fun loadAdForDefaultBanner(lifecycleOwner: LifecycleOwner, observer: Observer<AdLoadingEvent>)
fun inflateBigBanner(parent: ViewGroup, lifecycleOwner: LifecycleOwner)
fun loadAdForBigBanner(lifecycleOwner: LifecycleOwner, observer: Observer<AdLoadingEvent>)
fun displayFullScreenAd(
context: Context,
lifecycleOwner: LifecycleOwner,
observer: Observer<FullScreenAdEvent>
)
fun createGridViewHolder(parent: ViewGroup): AdViewHolder
fun getAdAdapterManager(): AdRecyclerView.AdAdapterManager
fun getAdLayoutManager(): AdRecyclerView.AdLayoutManager
}
- SDK initialization
fun init(context: Context)
- Inflate View, that will contain and display a standard banner ad.
It adds the created View to the passedparent
fun inflateDefaultBanner(parent: ViewGroup, lifecycleOwner: LifecycleOwner)
LifecycleOwner
is used to process the lifecycle methods of the object that caused this method (for example, canceling the loading of advertising data if the user returned to the previous screen).
Adform also requires calling lifecycle methods for its View.
- Initializes the loading of ad data.
Received data is returned toObserver<AdLoadingEvent>
fun loadAdForDefaultBanner(lifecycleOwner: LifecycleOwner, observer: Observer<AdLoadingEvent>)
- Inflate View for a "Big Banner", that will contain and display a
standard banner ad.
It adds the created View to the passedparent
fun inflateBigBanner(parent: ViewGroup, lifecycleOwner: LifecycleOwner)
LifecycleOwner
is used to process the lifecycle methods of the object that caused this method (for example, canceling the loading of advertising data if the user returned to the previous screen).
Adform also requires calling lifecycle methods for its View.- "Big Banner" is:
- Adform is an interactive ad with a given height.
- Leadbolt is a native banner with a height of 300dp.
- Inmobi there is the implementation of native advertising with given dimensions.
- Initializes the loading of ad data for a "Big Banner".
Received data is returned toObserver<AdLoadingEvent>
fun loadAdForBigBanner(lifecycleOwner: LifecycleOwner, observer: Observer<AdLoadingEvent>)
- Initializes the display of full-screen advertising.
Full-screen advertising events are returned toObserver<FullScreenAdEvent>
(for example, closing ads, ending downloads, etc.)fun displayFullScreenAd( context: Context, lifecycleOwner: LifecycleOwner, observer: Observer<FullScreenAdEvent> )
- Returns an object of the
AdViewHolder
class that extendsRecyclerView.ViewHolder
for further use inRecyclerView.Adapter
.fun createGridViewHolder(parent: ViewGroup): AdViewHolder
- Returns an object of the
AdRecyclerView.AdAdapterManager
class that manages the list of data displayed inRecyclerView
with the addition of advertisements to this listfun getAdAdapterManager(): AdRecyclerView.AdAdapterManager
- Returns an object of the
AdRecyclerView.AdAdapterManager
class, which in turn creates aRecyclerView.LayoutManager
, which will manage a specificAdProvider
implementation for displaying advertisements inRecyclerView
.
For example, for Adform, you need to use built-in mechanisms for displaying advertisements inRecyclerView
, but they do not support displaying advertisements in custom View like an item inGridLayoutManager
fun getAdLayoutManager(): AdRecyclerView.AdLayoutManager
For the payment system was used Stripe.