Skip to main content
Version: 3.0

Android - Present Paywall Builder paywalls in Observer mode

If you've customized a paywall using the Paywall Builder, you don't need to worry about rendering it in your mobile app code to display it to the user. Such a paywall contains both what should be shown within the paywall and how it should be shown.

note

This section refers to Observer mode only. If you do not work in Observer mode, refer to the Android - Present Paywall Builder paywalls topic instead.

Before you start presenting paywalls (Click to Expand)
  1. Set up initial integration of Adapty with the Google Play and with the App Store.
  2. Install and configure Adapty SDK. Make sure to set the observerMode parameter to true. Refer to our framework-specific instructions for iOS, for Android, for Flutter, for React Native, and for Unity.
  3. Create products in the Adapty Dashboard.
  4. Configure paywalls, assign products to them, and customize them using Paywall Builder in the Adapty Dashboard.
  5. Create placements and assign your paywalls to them in the Adapty Dashboard.
  6. Fetch Paywall Builder paywalls and their configuration in your mobile app code.
  1. Implement the AdaptyUiObserverModeHandler. The AdaptyUiObserverModeHandler's callback (onPurchaseInitiated) informs you when the user initiates a purchase. You can trigger your custom purchase flow in response to this callback like this:
val observerModeHandler =
AdaptyUiObserverModeHandler { product, paywall, paywallView, onStartPurchase, onFinishPurchase ->
onStartPurchase()
yourBillingClient.makePurchase(
product,
onSuccess = { purchase ->
onFinishPurchase()
//handle success
},
onError = {
onFinishPurchase()
//handle error
},
onCancel = {
onFinishPurchase()
//handle cancel
}
)
}

Also, remember to invoke these callbacks to AdaptyUI. This is necessary for proper paywall behavior, such as showing the loader, among other things:

Callback in KotlinCallback in JavaDescription
onStartPurchase()onStartPurchase.invoke()The callback should be invoked to notify AdaptyUI that the purchase is started.
onFinishPurchase()onFinishPurchase.invoke()The callback should be invoked to notify AdaptyUI that the purchase is finished successfully or not, or the purchase is canceled.
  1. 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,
viewConfiguration,
products,
eventListener,
personalizedOfferResolver,
tagResolver,
timerResolver,
observerModeHandler,
)

After the view has been successfully created, you can add it to the view hierarchy and display it.

Request parameters:

ParameterPresenceDescription
ProductsoptionalProvide an array of AdaptyPaywallProduct to optimize the display timing of products on the screen. If null is passed, AdaptyUI will automatically fetch the required products.
ViewConfigurationrequiredSupply an AdaptyViewConfiguration object containing visual details of the paywall. Use the Adapty.getViewConfiguration(paywall) method to load it. Refer to Fetch the visual configuration of paywall topic for more details.
EventListeneroptionalProvide an AdaptyUiEventListener to observe paywall events. Extending AdaptyUiDefaultEventListener is recommended for ease of use. Refer to Handling paywall events topic for more details.
PersonalizedOfferResolveroptionalTo indicate personalized pricing (read more ), implement AdaptyUiPersonalizedOfferResolver and pass your own logic that maps AdaptyPaywallProduct to true if the product's price is personalized, otherwise false.
TagResolveroptionalUse AdaptyUiTagResolver to resolve custom tags within the paywall text. This resolver takes a tag parameter and resolves it to a corresponding string. Refer to Custom tags in paywall builder topic for more details.
ObserverModeHandlerrequired for Observer modeThe AdaptyUiObserverModeHandler you've implemented in the previous step.
variationIdrequiredThe string identifier of the variation. You can get it using variationId property of the AdaptyPaywall object.
transactionrequired

For iOS, StoreKit1: an SKPaymentTransaction object.

For iOS, StoreKit 2: Transaction object.

For Android: String identifier (purchase.getOrderId()) of the purchase, where the purchase is an instance of the billing library Purchase class.