AppcoinsBillingClient
The AppcoinsBillingClient
is the main interface for handling in-app billing in your application. It provides a straightforward way to perform operations like querying purchases, retrieving product details, consuming purchases, managing billing flows and performing app related operations like app updates.
To use the AppcoinsBillingClient
, create a single instance in your application. Start by initializing it with the startConnection
method, passing a listener to track the connection status. Once the connection is established, you can safely call methods to handle in-app billing tasks.
Call endConnection
to release resources and prevent memory leaks once your application is being terminated. For best practices, instantiate the client in your Application
's onCreate
method and ensure cleanup in onDestroy
.
The AppcoinsBillingClient
supports both synchronous and asynchronous operations, offering flexibility to execute tasks on the UI thread or background threads. Take special attention to the methods that require to be executed in the background threads to avoid ANRs.
Always check the readiness of the client using the isReady
method before performing any operations related to the billing service to avoid inconsistent behaviors.
By following these guidelines, you can ensure a smooth and efficient in-app billing integration for your application.
Public Methods
consumeAsync
void consumeAsync(String token, ConsumeResponseListener consumeResponseListener)
Consumes a purchase, finalizing the transaction. Unconsumed purchases may lead to refunds.
Parameters
Name | Type | Description |
---|---|---|
token | String | The token identifying the purchase to be consumed. |
consumeResponseListener | ConsumeResponseListener | Listener to receive the status of the consume operation. |
endConnection
void endConnection()
Terminates the connection to the billing client.
getReferralDeeplink
ReferralDeeplink getReferralDeeplink()
Retrieves a deeplink to the correct store from which the application was installed.
This method must not be called on the Main/UI Thread.
Returns
A ReferralDeeplink
with the details of the request result.
isAppUpdateAvailable
boolean isAppUpdateAvailable()
Checks whether an update is available for the application.
Returns
Boolean value which specifies if there is an update available or not.
isReady
boolean isReady()
Checks whether the billing client is ready to process requests.
Returns
Boolean value which specifies if the client is ready or not.
launchAppUpdateDialog
void launchAppUpdateDialog(Context context)
Displays a dialog prompting the user to update the application if there is an update available. If the user agrees, the store page from where the application was installed is launched.
Parameters
Name | Type | Description |
---|---|---|
context | Context | The application context. |
launchAppUpdateStore
void launchAppUpdateStore(Context context)
Opens the store from where the application was installed, navigating to the application's page.
Parameters
Name | Type | Description |
---|---|---|
context | Context | The application context. |
launchBillingFlow
int launchBillingFlow(Activity activity, BillingFlowParams billingFlowParams)
Launches the billing flow for a specified SKU.
This method must not be called on the Main/UI Thread.
Returns
An integer value of the ResponseCode
.
Parameters
Name | Type | Description |
---|---|---|
activity | Activity | The activity used to launch the billing flow. |
billingFlowParams | BillingFlowParams | Parameters for the billing flow. |
onActivityResult (Deprecated)
boolean onActivityResult(int requestCode, int resultCode, Intent data)
This method is deprecated and no longer required in the billing integration.
Processes the result of a previously launched activity.
Returns
Boolean value which specifies if the result was processed successfully or not.
Parameters
Name | Type | Description |
---|---|---|
requestCode | Int | The request code from onActivityResult . |
resultCode | Int | The result code from onActivityResult . |
data | Intent | The intent data from onActivityResult . |
queryPurchases
PurchasesResult queryPurchases(String skuType)
Retrieves the purchases associated with the user based on the specified SKU type.
Returns
A PurchasesResult
containing the query results.
Parameters
Name | Type | Description |
---|---|---|
skuType | String | The type of purchase to query. Must be a valid SkuType . |
querySkuDetailsAsync
void querySkuDetailsAsync( SkuDetailsParams skuDetailsParams, SkuDetailsResponseListener onSkuDetailsResponseListener )
Fetches details of SKUs available in the application asynchronously.
Parameters
Name | Type | Description |
---|---|---|
skuDetailsParams | SkuDetailsParams | Parameters specifying the SKUs to query. |
onSkuDetailsResponseListener | SkuDetailsResponseListener | Listener for receiving the SKU details. |
startConnection
void startConnection(AppCoinsBillingStateListener listener)
Initializes a connection to the billing client.
Parameters
Name | Type | Description |
---|---|---|
listener | AppCoinsBillingStateListener | A listener to monitor connection state changes. |
Updated 13 days ago