Android Push Notifications with Supabase and Entrig

Entrig
Ib Entrig Team

Most push notification tutorials cover the basics: one user, one device, one notification. Real apps are messier. A group chat needs to notify the right people at the right time: the group owner when someone joins, everyone in a room when a message arrives, all users when a new group is created.

Each of those is a different recipient pattern: one-to-one, one-to-many via a join table, and broadcast. This tutorial builds all three in native Android with Kotlin, using a real Supabase schema, configured in the Entrig dashboard with no Edge Functions or custom backend code.


The schema

A minimal group chat app with four tables:

TableColumns
usersid, name, created_at
groupsid, name, created_by → users.id, created_at
group_membersgroup_id → groups.id, user_id → users.id, created_at
messagesid, content, group_id → groups.id, user_id → users.id, created_at

The three notifications we’re building:

  1. Member joins a group → notify the group owner (one-to-one)
  2. New message in a group → notify all members except the sender (one-to-many)
  3. New group created → notify all users except the creator (broadcast)

Set up the SDK

Add the dependency to your app’s build.gradle. The SDK requires Android 8.0 (API 26) or higher:

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

Initialize Entrig once at startup. The Application class is the natural place, but you can also do it in your launcher Activity:

import android.app.Application
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",
                autoOpenDeeplink = true
            )
        )
    }
}

Register the device against the Supabase Auth user ID right after sign-in. The userId you pass to Entrig.register() must be the Supabase Auth user ID (session.user.id). This is the ID Entrig uses to resolve which device to send to:

val session = Supabase.client.auth.currentSessionOrNull()
val userId = session?.user?.id ?: return

Entrig.register(userId) { success, error ->
    if (success) {
        // Device registered for notifications
    }
}

On Android 13 and above, the SDK requests the POST_NOTIFICATIONS permission automatically during register(). Android delivers the permission result to your Activity, not to the SDK, so you must forward it:

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

When the user signs out, unregister the device so it stops receiving pushes:

Entrig.unregister { success, error ->
    if (success) {
        // Device unregistered
    }
}

See the Android SDK docs for the full setup including manual permission handling and foreground notification options.


Configure the notifications

Each notification is created in the Entrig dashboard in three steps: Trigger (when), Users (who), Message (what). None of this is platform specific, it runs on the Entrig backend against your Supabase schema. The three tabs below walk through each notification type.

When a user joins a group, the person who created that group should know. This is a one-to-one notification: one join event, one recipient, found by navigating through two foreign keys to reach the owner.

Trigger

  • Table: group_members

  • Event: INSERT

  • Condition: group_members.user_idgroups.created_by (row value)

    Skip the notification when the joiner is the owner. Apps typically add the creator to group_members at the moment the group is created, so without this guard the owner would get a “someone joined your group” push about themselves.

Users

  • Users table: users

  • Connection type: Direct

    Direct means the trigger event maps to a single user. Entrig follows foreign keys to find them.

  • Path: group_members.group_id → groups → created_by → users.id

    Entrig reads your schema and auto-detects this path. Select it from the list. It follows group_id to the groups table, reads created_by, and resolves that to the users table.

  • Recipient filters: none

Message

Add payload fields so the title and body can reference them:

  • groups.name: name of the group
  • users.name: name of the user who joined

Set the title and body:

FieldValue
TitleNew member in {{groups.name}}
Body{{users.name}} just joined your group

Set the deeplink so a tap lands on the group. Placeholders are rendered at send time, so the URL arrives with the real value:

groupchat://chat/{{group_members.group_id}}

When a message is sent, every member of that group should receive a notification, except the sender. This uses an indirect connection through the group_members join table, with a recipient filter to exclude the sender using a row value comparison.

Trigger

  • Table: messages
  • Event: INSERT
  • Conditions: none

Users

  • Users table: users

  • Connection type: Indirect via Join Table

    Indirect means the trigger event maps to multiple users through a relationship table.

  • Path: messages.group_idgroup_members (match on group_id) → user_idusers.id

    Entrig takes the group_id from the new message row, finds all matching rows in group_members, and from each of those resolves user_id to a registered device.

  • Recipient filter: group_members.user_idmessages.user_id (row value)

    This is the exclude-sender step. Set the filter value source to row value and select messages.user_id. Entrig will skip any group_members row where the user_id matches the sender.

Message

Add payload fields:

  • groups.name: group name for the notification title
  • users.name: sender’s name
  • messages.content: the message text

Set the title and body:

FieldValue
Title{{groups.name}}
Body{{users.name}}: {{messages.content}}

Set the deeplink so a tap opens the group the message was sent in:

groupchat://chat/{{messages.group_id}}

When a new group is created, every other user in the app should be notified so they can choose to join. This is a broadcast: the trigger table has no join path to users, so Entrig notifies everyone registered, filtered to exclude the creator.

Trigger

  • Table: groups
  • Event: INSERT
  • Conditions: none

Users

  • Users table: users

  • Connection type: Broadcast

    Broadcast notifies all users in the users table when the event fires. No join table needed.

  • Recipient filter: users.idgroups.created_by (row value)

    Set the filter value source to row value and select groups.created_by. This excludes the creator from the broadcast. They don’t need to be told about a group they just made.

Message

Add payload fields:

  • groups.name: the new group’s name
  • users.name: the creator’s name

Set the title and body:

FieldValue
TitleNew group: {{groups.name}}
Body{{users.name}} created a new group. Tap to join

Set the deeplink so a tap opens the new group:

groupchat://chat/{{groups.id}}

Handle notification taps

All three notifications carry a deeplink of the form groupchat://chat/<group-id>. Because we initialized with autoOpenDeeplink = true, the SDK fires an ACTION_VIEW intent when the notification is tapped and Android routes it to whichever activity registers that scheme. No tap listener or manual parsing is required.

Register the scheme on your chat activity in AndroidManifest.xml. Use singleTop so an already-open chat is reused instead of stacked:

<activity
    android:name=".ChatActivity"
    android:exported="true"
    android:launchMode="singleTop">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="groupchat" android:host="chat" />
    </intent-filter>
</activity>

Read the group ID from the incoming intent. The same code handles both a cold start (the app was killed, so the tap launches the activity through onCreate) and a warm tap (the app was already running, so the intent arrives in onNewIntent):

class ChatActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_chat)
        resolveIntent(intent)
    }

    override fun onNewIntent(intent: Intent) {
        super.onNewIntent(intent)
        setIntent(intent)
        resolveIntent(intent)
    }

    private fun resolveIntent(intent: Intent) {
        if (intent.action == Intent.ACTION_VIEW) {
            val groupId = intent.data?.lastPathSegment   // groupchat://chat/<group-id>
            if (groupId != null) loadChat(groupId)
        } else {
            // Existing in-app navigation path (extras from your rooms list)
            val groupId = intent.getStringExtra("group_id") ?: return
            loadChat(groupId)
        }
    }
}

The deeplink only carries the group ID, so loadChat() fetches the group name from Supabase. That keeps the notification payload small and the URL stable.

Prefer to handle the tap yourself? Leave autoOpenDeeplink at its default of false and read the URL from a listener instead:

Entrig.setOnNotificationOpenedListener { notification ->
    notification.deeplink?.let { url ->
        val groupId = Uri.parse(url).lastPathSegment
        // navigate to ChatActivity with groupId
    }
}

Pick one approach. With autoOpenDeeplink = true the listener still fires, so do not also navigate from it or you will open the screen twice.

To react to a notification while the app is in the foreground (for example to refresh the message list in place instead of showing a banner), set a foreground listener:

Entrig.setOnForegroundNotificationListener { notification ->
    // notification.title, notification.body, notification.type, notification.data
}

Test it

Push notifications require a real device. With your app running, trigger each notification by inserting a row from the Supabase dashboard or SQL editor:

-- Notification 1: member joins a group
INSERT INTO group_members (group_id, user_id)
VALUES ('your-group-id', 'joining-user-id');

-- Notification 2: new message
INSERT INTO messages (content, group_id, user_id)
VALUES ('Hey everyone!', 'your-group-id', 'sender-user-id');

-- Notification 3: new group created
INSERT INTO groups (name, created_by)
VALUES ('Weekend Plans', 'creator-user-id');

Each insert should deliver the notification to the right device within a few seconds.


The three notifications in this tutorial cover the full range of what Entrig supports: Direct for targeted one-to-one, Indirect for group-aware delivery, and Broadcast for app-wide announcements. The same patterns apply to any app: e-commerce orders, task assignments, social follows.

Full SDK reference at entrig.com/docs.


Read the Push Notifications for Supabase overview for a comparison of the manual setup versus Entrig.


Start free with Entrig and get this running on your own Supabase project in minutes. More at entrig.com.