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.
Add the SDK to your project
Configure the Nami SDK
Show a paywall in your app
React to a purchase to grant access to paid content or features
We'll run through each of these below.
Prerequisites
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' }
}
}
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"
}
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()
}
}
Configure the SDK
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