subscribe

open fun subscribe(activity: Activity, subsId: String): String

Subscribes to a product, letting the library pick the offer (the offer whose id matches trialId if configured, otherwise Play's last offer).

See also

to subscribe to one specific offer.


open fun subscribe(activity: Activity, subsId: String, @Nullable offerToken: String): String

Subscribes to one specific offer of a subscription product.

This is the method a multi-offer paywall needs. A single subscription product routinely carries several offers — a base plan, a 7-day free trial, a 50%-off introductory offer — and Play returns only the ones the user is actually eligible for. Enumerate them with getOffers, render them, then pass the token of the one the user chose.

When offerToken is null this behaves exactly like subscribe.

Return

a human-readable result string; "Billing flow started" on success.

Since

4.4.0

Parameters

activity

the launching activity; must not be finishing.

subsId

subscription product id.

offerToken

offer token from getOfferToken, or null to let the library choose.


open fun subscribe(activity: Activity, @NonNull offer: OfferInfo): String

Subscribes to the exact offer described by offer.

Return

a human-readable result string; "Billing flow started" on success.

Since

4.4.0

Parameters

activity

the launching activity; must not be finishing.

offer

an offer obtained from getOffers.