Skip to content

Android Integration

Integrate Entrig in 4 steps:

Install → Initialize → Register → Handle


Requirements

Android 8.0 (API 26) or higher.


Installation

Add the dependency to your app’s build.gradle:

dependencies {
implementation 'com.entrig:entrig:1.0.0'
}

Initialization

Initialize Entrig in your Application class:

import com.entrig.sdk.Entrig
import com.entrig.sdk.models.EntrigConfig
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
Entrig.initialize(this, EntrigConfig(apiKey = "YOUR_ENTRIG_API_KEY"))
}
}

Your API key is available in the Entrig dashboard under project settings.


Registering Devices

Call Entrig.register() with the user’s ID when they sign in, and Entrig.unregister() when they sign out.

// On sign in
Entrig.register(userId)
// On sign out
Entrig.unregister()

The userId you pass here must match the user identifier field configured in your notification in the Entrig dashboard. If they do not match, Entrig cannot resolve the recipient.

We recommend using the Supabase Auth user ID as the userId. It is stable, always available when using Supabase Auth, and is typically the ID that other tables in your database already reference.

Permission forwarding (Android 13+)

On Android 13+, register() automatically requests the POST_NOTIFICATIONS permission. You must forward the result from your Activity:

override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
Entrig.onRequestPermissionsResult(requestCode, grantResults)
}

Android delivers permission results to the Activity, not to libraries directly. This forwarding is required for the SDK to receive the result.


Handling Notifications

When a notification arrives, your app can be in one of three states:

  • Foreground - app is open and visible
  • Background - app is running but not visible
  • Terminated - app is fully closed

Entrig handles displaying notifications in all three states. The only thing you need to handle is what happens when the user taps a notification.

To handle notification taps:

Entrig.setOnNotificationOpenedListener { notification ->
// navigate based on notification.type or notification.data
}

If the app was fully terminated when the notification was tapped, the listener may not be registered in time. Use getInitialNotification() on startup instead:

val notification = Entrig.getInitialNotification()
if (notification != null) {
// app was launched by tapping a notification
// returns null after being called once
}

By default, notifications are also shown as a banner when the app is in the foreground. You can turn this off:

Entrig.initialize(this, EntrigConfig(
apiKey = "YOUR_ENTRIG_API_KEY",
showForegroundNotification = false
))

NotificationEvent fields:

FieldDescription
titleNotification title
bodyNotification body
typeCustom type identifier set in the dashboard
dataCustom payload data from your database

Permission Handling

By default, register() requests notification permission automatically. To handle permissions yourself:

val config = EntrigConfig(
apiKey = "YOUR_ENTRIG_API_KEY",
handlePermission = false
)
Entrig.initialize(this, config)
// Then request manually before registering
Entrig.requestPermission(this) { granted ->
if (granted) {
Entrig.register(userId)
}
}

The onRequestPermissionsResult forwarding is still required when using manual permission handling.