SDK Integration

How to setup the Amazon Appstore Android Nami SDK

Please make sure you have completed the setup of your app on the Nami Control Center for all these steps to be successful.

Adding Nami to your app has a few steps for a basic app.

  1. Add the SDK to your project

  2. Configure the Nami SDK

  3. Show a paywall in your app

  4. React to a purchase to grant access to paid content or features

We'll run through each of these below.

Prerequisites

Amazon Appstore Android Requirements

  • Android SDK minimum version 22

  • SDK builds target Android 12 (API version 31)

  • SDK has been built with Java v8 and Kotlin v1.6.10

If you haven't already done so, be sure your app includes a public key provided through the Amazon Appstore Developer Console.

This key is used to create a secure channel between your app and the Amazon Appstore. The Nami SDK for Amazon Appstore requires this secure connection to exist.

For more details, please visit Amazon's documentation on configuring your public key.

Add the SDK to your project

Our Android SDK is available via our Maven repository. Add the following code snippet to your project's build.gradle to add the Nami SDK to your project.

allprojects {
    repositories {
        google()
        mavenLocal()
        maven { url "https://packages.namiml.com/NamiSDK/Amazon/"}
        maven { url 'https://jitpack.io' }
    }
}

Enterprise customers may have a custom Maven repo. Contact Team Nami to learn more and make sure you are referencing the correct repository.

Then in the build.gradle for your app add the following code, replacing the version number with whichever version of the Nami SDK you would like to run.

dependencies {
 		implementation "com.namiml:sdk-amazon:3.1.5" 
}

Release notes for the Nami Android SDK are available here.

Add compileOptions for Java 8 compatibility in your appbuild.gradle.

android {
  // Configure only for each module that uses Java 8
  // language features (either in its source code or
  // through dependencies).
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
  // For Kotlin projects
  kotlinOptions {
    jvmTarget = JavaVersion.VERSION_1_8.toString()
  }
}

Supporting Android SDK minimum version 25

If your app need to support Android SDK minimum version 25, see this doc for two additional steps to enable the Nami SDK to work properly.

Configure the SDK

Use Android Studio to Get Code Documentation

The Nami SDK was built with Dokka and if you use Android Studio, you'll get helpful code completions and documentation about methods.

We recommend that you configure the Nami SDK as early in your app's launch as possible. This will ensure the SDK is ready to receive and process purchases.

The best spot to do this is in the onCreate() method in your class that creates your Application and inherits from Application(). Here's a full code example.

You'll need to go find your App Platform ID in the Control Center > Integrations > Amazon Appstore for this step.

import com.namiml.Nami
import com.namiml.NamiConfiguration
import com.namiml.NamiLogLevel
  
class DemoApplication : Application() {
    
  override fun onCreate() {
    super.onCreate()
    Nami.configure(
      NamiConfiguration.build(this, "YOUR_APP_PLATFORM_ID") {
        LogLevel = NamiLogLevel.INFO.takeIf { BuildConfig.DEBUG } ?: NamiLogLevel.WARN
      }
    )
  }
}

Nami recommends setting the log level to WARN for apps on the store. INFO may be helpful during development to better understand what is going on. DEBUG level has a lot of information and is likely only helpful to the Nami support team.

Show a paywall

Now that you have the SDK configured, let's show a paywall in your app.

This step requires that you have designed a paywall and attached it to a live campaign.

import com.namiml.campaign.NamiCampaignManager
import com.namiml.campaign.LaunchCampaignResult

import android.util.Log
  
const val LOG_TAG = "ExampleApp"
  
class ExampleActivity : AppCompatActivity() {
  
   override fun onCreate(savedInstanceState: Bundle?) {

      NamiCampaignManager.launch(this) { result ->
        when (result) {
            is LaunchCampaignResult.Success -> {
                Log.d(LOG_TAG, "Launch Campaign Success")
            }
            is LaunchCampaignResult.Failure -> {
                Log.d(LOG_TAG, "Launch Campaign Error -> ${result.error}")
            }
        }
      }
   
   	}
  }
}

Grant access to paid app features

Once a user has made a purchase, you'll need to make sure to give them access to the content and features in your app that require a purchase. This is managed on the Nami platform through our entitlement engine.

The first option is to check whether a specific entitlement is active. This is done with the following code.

if (NamiEntitlementManager.isEntitlementActive("premium_access")) {
 	// allow access to premium app features 
}

Nami also triggers a callback any time there is a change to the state of an entitlement. In the callback the full list of currently active entitlements is provided. You can use this to store the state of whether a user has access to premium features locally in your app.

It is important that any callbacks are created as early in the app launch as possible. We recommend adding the callback handlers in the NamiSetup method in your AppDelegate.cs.

NamiEntitlementManager.registerEntitlementChangeListener { activeEntitlements ->
  // process active entitlements to grant access
  for (val ent in activeEntitlements) {
    val ent_id = ent.referenceId;
    // use the active entitlements reference IDs to grant
    // access to premium app features
  }
}

That's all the basics to get up and running with Nami for Google Play - Android apps.

Next Steps

🎉 Congrats on having the basics in place!

Now you are ready to go further based upon your use cases:

Last updated