Android – Presenting visual paywalls
In order to display the visual paywall on the device screen, you must first configure it. To do this, call the method AdaptyUI.getPaywallView()
or create the AdaptyPaywallView
directly:
val paywallView = AdaptyUI.getPaywallView(
activity,
paywall,
products,
viewConfiguration,
AdaptyPaywallInsets.of(topInset, bottomInset),
eventListener,
personalizedOfferResolver,
)
//======= OR =======
val paywallView =
AdaptyPaywallView(activity) // or retrieve it from xml
...
with(paywallView) {
setEventListener(eventListener)
showPaywall(
paywall,
products,
viewConfiguration,
AdaptyPaywallInsets.of(topInset, bottomInset),
personalizedOfferResolver,
)
}
AdaptyPaywallView paywallView = AdaptyUI.getPaywallView(
activity,
paywall,
products,
viewConfiguration,
AdaptyPaywallInsets.of(topInset, bottomInset),
eventListener,
personalizedOfferResolver
);
AdaptyPaywallView paywallView =
new AdaptyPaywallView(activity); //add to the view hierarchy if needed, or you receive it from xml
...
paywallView.setEventListener(eventListener);
paywallView.showPaywall(paywall, products, viewConfiguration, AdaptyPaywallInsets.of(topInset, bottomInset), personalizedOfferResolver);
<com.adapty.ui.AdaptyPaywallView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" />
After the view has been successfully created, you can add it to the view hierarchy and display on the screen of the device.
If you get AdaptyPaywallView
not by calling AdaptyUI.getPaywallView()
, you will also need to call .setEventListener()
and .showPaywall()
methods.
Request parameters:
- Paywall (required): an
AdaptyPaywall
object, for which you are trying to get a screen representation. - Products (optional): an
AdaptyPaywallProduct
array. Pass this value in order to optimize the display time of the products on the screen. If you passnull
,AdaptyUI
will automatically fetch the required products. - ViewConfiguration (required): an
AdaptyViewConfiguration
object containing information about the visual part of the paywall. To load it, use theAdapty.getViewConfiguration(paywall)
method. Read more. - Insets (required): an
AdaptyPaywallInsets
object containing information about the area overlapped by system bars, to create vertical margins for the content. If neither status bar nor navigation bar overlap theAdaptyPaywallView
, please passAdaptyPaywallInsets.NONE
. Only in case it's fullscreen (i.e. the system bars do overlap part of your UI), you can obtain the insets the following way:
import androidx.core.graphics.Insets
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
//create extension function
fun View.onReceiveSystemBarsInsets(action: (insets: Insets) -> Unit) {
ViewCompat.setOnApplyWindowInsetsListener(this) { _, insets ->
val systemBarInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars())
ViewCompat.setOnApplyWindowInsetsListener(this, null)
action(systemBarInsets)
insets
}
}
//and then use it with the view
paywallView.onReceiveSystemBarsInsets { insets ->
val paywallInsets = AdaptyPaywallInsets.of(insets.top, insets.bottom)
paywallView.showPaywall(paywall, products, viewConfig, paywallInsets, productTitleResolver)
}
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
...
ViewCompat.setOnApplyWindowInsetsListener(paywallView, (view, insets) -> {
Insets systemBarInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars());
ViewCompat.setOnApplyWindowInsetsListener(paywallView, null);
AdaptyPaywallInsets paywallInsets =
AdaptyPaywallInsets.of(systemBarInsets.top, systemBarInsets.bottom);
paywallView.showPaywall(paywall, products, viewConfiguration, paywallInsets, productTitleResolver);
return insets;
});
- EventListener (optional): an
AdaptyUiEventListener
, for observing paywall events. We recommend extending theAdaptyUiDefaultEventListener
so you don't need to override all the methods. Read more. - PersonalizedOfferResolver (optional): In case you want to indicate whether the price is personalized (read more), you can implement
AdaptyUiPersonalizedOfferResolver
and pass your own logic that mapsAdaptyPaywallProduct
totrue
, if the price of the product is personalized, otherwisefalse
.
Returns:
- an
AdaptyPaywallView
object, representing the requested paywall screen.
Updated 2 months ago