Mobile SDK
Android SDK
Install, initialise, identify, track, handle push and deep links on Android.
Install#
Add the nerja-sdk module (its only dependency is Firebase Messaging) and your app's google-services.json. The SDK's manifest is merged automatically.
include ':nerja-sdk'
dependencies { implementation project(':nerja-sdk') }Initialise#
// Application.onCreate()
Nerja.init(this, new NerjaConfig.Builder()
.baseUrl("https://api.nerja.ai")
.appKey("nak_pk_live_YOUR_KEY")
.build()); // add .firebase(...) only if you have no google-services.jsonThe SDK sends app_open on a cold start and registers the push token by itself. Your appId defaults to the application id; override with .appId("com.shop.app") if your key allows a different one.
Identify and track#
// after login
Nerja.identify("user_42", userHashFromYourBackend /* or null */, traits);
// anywhere
Nerja.track("add_to_cart", Map.of("product_id", "sku-1", "price", 249));
// logout
Nerja.logout();userHash is only needed when you enabled signed user ids. Compute it on your server; never put the secret in the app.
Push notifications#
- Android 13+ needs the user's permission: call
Nerja.requestNotificationPermission(activity)at a moment that makes sense (e.g. after the first order). - Pushes that arrive while the app is closed are shown by the system; the SDK reports the tap.
- Pushes while the app is open are shown by the SDK with image and a button.
Deep links#
Nerja.setLinkHandler((ctx, link, data) -> {
// link = myshop://product/42 (or the website URL when the push had no app link)
startActivity(ProductActivity.intentFor(ctx, link));
return true; // handled — otherwise the SDK falls back to the website
});For singleTop activities also call Nerja.handleIntent(this, intent) from onNewIntent. More: Deep links.
Permissions#
See the full list with reasons in Permissions explained.
Prefer to talk it through? Book a 30-minute call with the Nerja team.
Something unclear or missing? Email support@nerja.ai and we will improve this page.