Skip to main content

Tonos Android SDK

Version: 1.1.3


This service allows you to add Tonos into your Android application. This section of the documentation provides detailed steps on how to succesfully complete this task.

Requirements

ItemNotes
Android StudioDownload & Install Android Studio.
Android 4.4 (API 19)Your app must be leveraging at least this minimum OS version.
Tonos LicenseRequest a license by contacting Tonos at tonos@gjirafa.tech

Adding the Tonos SDK

  1. From Android Studio, open your project.
  2. Open settings.gradle if you're using dependency resolution management. Otherwise, open a project-level build.gradle file.
  3. Add the necessary repositories.
repositories {
...
maven { url 'https://pkgs.dev.azure.com/gjirafadev/_packaging/AndroidResources/maven/v1' }
maven {
url 'https://pkgs.dev.azure.com/gjirafadev/Tonos/_packaging/AndroidTonos/maven/v1'
credentials {
username "{Your username}"
password "{Your password}"
}
}
}
NOTE

Replace the username and password in order for Tonos to compile successfully.

  1. Navigate to the build.gradle app level under the dependencies folder. Add the following code snippet.
build.gradle

implementation "tech.gjirafa:tonos:{TAG}"

NOTE

Replace {TAG} with the latest version of the Tonos SDK.

  1. In the app level build.gradle file, configure compileOptions to support Java 8 language, multidex, and also configure the appAuthRedirectScheme.
build.gradle

android {
defaultConfig {
...
minSdkVersion 19
multiDexEnabled true
android.defaultConfig.manifestPlaceholders = ['appAuthRedirectScheme': '{YourApplicationId}']
}
...
compileOptions {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
}

NOTE

Note: Replace {YourApplicationId} for appAuthRedirectScheme

  1. Sync Gradle

You have now successfully added the Tonos SDK into your application

Configuring the Tonos SDK

In order to complete the Tonos SDK import process, you must complete the following steps.

  1. Call Tonos.setup() on your running activity.
ParameterDescription
appCompatActivityActivity in which you'll use Tonos
appIdProvided from Tonos when setting up your application

The code snippets below provide information on how to execute this process using either Kotlin or Java.

class YourActivity : AppCompatActivity(R.layout.activity_demo) {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Tonos.setup(appCompatActivity = this, appId = "appId")
}
}
NOTE

Replace the appId parameter with your application ID

  1. Call Tonos.auth.onActivityResult() by overriding the onActivityResult() of your running activity.
ParameterDescription
requestCodeFound onActivityResult() response
dataFound onActivityResult() response

The code snippets below provide information on how to execute this process using either Kotlin or Java.

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
// Handling onActivityResult for authenticator login/logout :)
Tonos.auth.onActivityResult(requestCode, data)
}

Displaying offers

In order to display offers in your application from Tonos, you must invoke the Tonos.fetchOffer() function.

The table below describes the parameters of this function.

ParamTypeDescription
contentIdStringUsed to display offers based on it. One contentId represents one page.
containerView (Optional)Used to display the offer if the offer we're displaying is an inline offer.
fetchOfferDelegateFetchOfferDelegate (Optional)Used to invoke events back to the fetchOffer() method by letting </> know if the offer has loaded successfully or has failed to load.

The code snippets below provide information on how to execute this process using either Kotlin or Java.

Tonos.fetchOffers("YourContentId", yourContainerView, object : FetchOfferDelegate {
override fun onStateChanged(state: FetchOfferState) {
if (state == FetchOfferState.OFFER_FAILED_TO_FETCH) {
// Failed to fetch offer
} else {
// Offer loaded successfully
}
}
})
NOTE

Replace the contentId & containerView with your own values.

Additionally, you can invoke the Tonos.stopOffer() in order to dismiss any modal showing offers & cancel the last fetching offer. This is usually used when you start fetchOffer() and the user navigates back to previous page, in which case we need to stop fetching the last offer & dismiss if it has shown already.

The code snippets below provide information on how to execute this process using either Kotlin or Java.

Tonos.stopOffer()

Loader customization

If you'd like to customize or enable/disable provided loader, you can use the following functions:

Tonos.setUseLoader

ParamTypeDescription
useLoaderBooleanEnable or disable loader.

The code snippets below provide information on how to execute this process using either Kotlin or Java.

Tonos.setUseLoader(true)

Tonos.setLoaderStyle()

ParamTypeDescription
loaderStyleLoaderStyleData class in which you can change values in order to modify the loader.
ParamTypeDescriptionDefault Value
backgroundOverlayColorIntSet your desired background overlay color."#103e3e3e".toColorInt()
cardBackgroundColorIntSet your desired card background color."#FFFFFF".toColorInt()
cardCornerRadiusIntSet your desired card corner radius.15
indicatorColorIntSet your desired indicator color."#000000".toColorInt()

The code snippets below provide information on how to execute this process using either Kotlin or Java.

Tonos.setLoaderStyle(LoaderStyle(
backgroundOverlayColor = "103e3e3e".toColorInt(),
cardBackgroundColor = "FFFFFF".toColorInt(),
cardCornerRadius = 12,
indicatorColor = "#000000".toColorInt()
))

Analytics

When users interact with offers, their actions trigger different events. Below you will find some methods of listening to these events listed along with a desription for each of them.

Implementing the delegate

The code snippets below provide information on how to execute this process using either Kotlin or Java.

Tonos.setStateDelegate(object: TonosStateDelegate {
override fun onStateChanged(event: TonosEvent<Any>) {
if (event.state == TonosState.ACCESSIBLE) {
// Tonos is ready for use
}
}
})

You can also listen for events in a class level. In order to do so, follow these instructions.

  1. On the onCreate() method of your fragment/activity, add the following code snippet.
Tonos.setStateDelegate(this)
  1. Implement the delegate on our class.
class DemoActivity : AppCompatActivity(R.layout.activity_demo), TonosStateDelegate {
...
}
  1. Override the onStateChanged() method.
override fun onStateChanged(event: TonosEvent<Any>) {
if (event.state == TonosState.ACCESSIBLE) {
// Tonos ready for use.
}
}

Tonos events

ParamTypeDescription
stateTonosStateNotifies user about different states (Check TonosState model table below).
valueAnyIf there are any data available which can be passed to our user, they'll be done using a value parameter.

TonosState

ACCESSIBLE
EventACCESSIBLE
DescriptionFired wen Tonos is ready for use.
Return Type
APP_INITIALIZE
EventAPP_INITIALIZE
DescriptionFired when the application is initialized.
Return Type
PAGE_INITIALIZE
EventPAGE_INITIALIZE
DescriptionFired when the page is initialized.
Return Type
LOGIN_SHOW
EventLOGIN_SHOW
DescriptionFired when the login form is shown.
Return Type
LOGIN_SUCCESS
EventLOGIN_SUCCESS
DescriptionFired when the login process is successful.
Return Type
OFFER_SHOWN
EventOFFER_SHOWN
DescriptionFired when the offer is shown.
Return Type
OFFER_CLOSED
EventOFFER_CLOSED
DescriptionFired when the offer is closed.
Return Type
CHECKOUT_SHOW
EventCHECKOUT_SHOW
DescriptionFired when the checkout for is shown.
Return Type
CHECKOUT_ABANDONED
EventCHECKOUT_ABANDONED
DescriptionFired when the checkout process is abandoned.
Return Type
CHECKOUT_SUCCESS
EventCHECKOUT_SUCCESS
DescriptionFired when the checkout process is successful.
Return Type
CHECKOUT_FAILED
EventCHECKOUT_FAILED
DescriptionFired when the checkout process fails.
Return Type
PLAN_SELECTED
EventPLAN_SELECTED
DescriptionFired when a subscription plan is selected.
Return Type
PAYMENT_SHOW
EventPAYMENT_SHOW
DescriptionFired when a payment is shown.
Return Type
FAILED_TO_INITIALIZE_APP
EventFAILED_TO_INITIALIZE_APP
DescriptionFired when the aplication failed to initialize.
Return Type
FAILED_FETCHING_CONFIGURATION_FROM_AUTHORITY
EventFAILED_FETCHING_CONFIGURATION_FROM_AUTHORITY
DescriptionFired when the configuration fetching from authority fails.
Return Type
AUTHENTICATOR_READY
EventAUTHENTICATOR_READY
DescriptionFired when the authenticator is ready.
Return Type
FAILED_TO_USE_AUTHENTICATOR_SERVICE
EventFAILED_TO_USE_AUTHENTICATOR_SERVICE
DescriptionFired when the authenticator service fails to use.
Return Type
FAILED_FETCHING_TOKEN
EventFAILED_FETCHING_TOKEN
DescriptionFired when the token fails to be fetched.
Return Type
FAILED_LOGGING_OUT_USER
EventFAILED_LOGGING_OUT_USER
DescriptionFired when the logout process fails.
Return Type
STARTING_BILLING_CONNECTION
EventSTARTING_BILLING_CONNECTION
DescriptionFired when the billing connection starts.
Return Type
BILLING_SETUP_FINISHED
EventBILLING_SETUP_FINISHED
DescriptionFired when the billing setup finishes.
Return Type
BILLING_SERVICE_DISCONNECTED
EventBILLING_SERVICE_DISCONNECTED
DescriptionFired when the billing service is disconnected.
Return Type
STARTING_AUTHENTICATOR
EventSTARTING_AUTHENTICATOR
DescriptionFired when the authenticator starts.
Return Type
PROCESSING_AUTHENTICATOR_RESULTS
EventPROCESSING_AUTHENTICATOR_RESULTS
DescriptionFired when the authenticator is processing results.
Return Type
FETCHING_CONSUMABLE_PURCHASE_HISTORY
EventFETCHING_CONSUMABLE_PURCHASE_HISTORY
DescriptionFired when the consumable purcahse history is being fetched.
Return Type
FETCHING_NON_CONSUMABLE_PURCHASE_HISTORY
EventFETCHING_NON_CONSUMABLE_PURCHASE_HISTORY
DescriptionFired when the non consumable history is being fetched.
Return Type
FETCHING_PURCHASE_HISTORY
EventFETCHING_PURCHASE_HISTORY
DescriptionFired when the purchase history is being fetched.
Return Type
STARTING_ACKNOWLEDGE_PURCHASE
EventSTARTING_ACKNOWLEDGE_PURCHASE
DescriptionFired when the acknowledge purchase is starting.
Return Type
STARTING_CONSUME_PURCHASE
EventSTARTING_CONSUME_PURCHASE
DescriptionFired when the consume purchase is starting.
Return Type
FETCHING_PRODUCT_DETAILS_FROM_STORE
EventFETCHING_PRODUCT_DETAILS_FROM_STORE
DescriptionFired when the product details from the store are being fetched.
Return Type
FAILED_FETCHING_PRODUCT_DETAILS
EventFAILED_FETCHING_PRODUCT_DETAILS
DescriptionFired when the product details failed to be fetched.
Return Type
STARTING_PURCHASE_FLOW
EventSTARTING_PURCHASE_FLOW
DescriptionFired when the purchase flow is starting.
Return Type
FAILED_TO_FETCH_OFFER
EventFAILED_TO_FETCH_OFFER
DescriptionFired when the offer failed to be fetched.
Return Type
FAILED_TO_FETCH_TEMPLATE
EventFAILED_TO_FETCH_TEMPLATE
DescriptionFired when the offer template failed to be fetched.
Return Type
FAILED_TO_FETCH_CHECKOUT
EventFAILED_TO_FETCH_CHECKOUT
DescriptionFired when the checkout failed to be fetched.
Return Type
FAILED_TO_PROCESS_PURCHASE
EventFAILED_TO_PROCESS_PURCHASE
DescriptionFired when the purchase was not processed.
Return Type
CLOSE_OFFER_MODAL_REQUESTED
EventCLOSE_OFFER_MODAL_REQUESTED
DescriptionFired when the requested offer modal is closed.
Return Type

Additional methods

We also offer additional methods for Store & Auth. Methods we provide are:

  • Auth
    • isAuthReady()
    • startAuthenticator()
    • endSession()
  • Store
    • isBillingClientReady()
    • isConnected()
    • startConnection()
    • endConnection()
    • getProduct()
    • buyProduct()
    • State
      • acknowledgePurchase()
      • consumePurchase()
    • History
      • fetchNonConsumablePurchaseHistory()
      • fetchConsumablePurchaseHistory()
      • fetchPurchaseHistory()