Skip to content

[DX-286] Kotlin push guide#3216

Open
maratal wants to merge 2 commits intoDX-287-web-push-guidefrom
DX-286-kotlin-push-guide
Open

[DX-286] Kotlin push guide#3216
maratal wants to merge 2 commits intoDX-287-web-push-guidefrom
DX-286-kotlin-push-guide

Conversation

@maratal
Copy link
Collaborator

@maratal maratal commented Feb 19, 2026

Description

Kotlin push guide

Checklist

@coderabbitai
Copy link

coderabbitai bot commented Feb 19, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch DX-286-kotlin-push-guide

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@maratal maratal added the review-app Create a Heroku review app label Feb 19, 2026
@maratal maratal changed the base branch from main to DX-287-web-push-guide February 19, 2026 16:28
@ably-ci ably-ci temporarily deployed to ably-docs-dx-286-kotlin-mmwrxx February 19, 2026 16:29 Inactive
@maratal maratal force-pushed the DX-286-kotlin-push-guide branch from 65ab558 to e106ea1 Compare February 22, 2026 16:52
@ably-ci ably-ci temporarily deployed to ably-docs-dx-286-kotlin-mmwrxx February 22, 2026 16:52 Inactive
@maratal maratal force-pushed the DX-286-kotlin-push-guide branch from e106ea1 to a20acb1 Compare February 22, 2026 22:29
@ably-ci ably-ci temporarily deployed to ably-docs-dx-286-kotlin-mmwrxx February 22, 2026 22:29 Inactive
@maratal maratal force-pushed the DX-286-kotlin-push-guide branch from a20acb1 to 885f61b Compare February 22, 2026 22:46
@ably-ci ably-ci temporarily deployed to ably-docs-dx-286-kotlin-mmwrxx February 22, 2026 22:47 Inactive
@maratal maratal force-pushed the DX-286-kotlin-push-guide branch from 885f61b to 65fb475 Compare February 22, 2026 23:11
@ably-ci ably-ci temporarily deployed to ably-docs-dx-286-kotlin-mmwrxx February 22, 2026 23:12 Inactive
@maratal maratal marked this pull request as ready for review February 22, 2026 23:28
@maratal maratal requested review from GregHolmes and ttypic February 22, 2026 23:28
@maratal maratal force-pushed the DX-287-web-push-guide branch from 7205395 to 94ce859 Compare February 24, 2026 15:28
Copy link
Contributor

@GregHolmes GregHolmes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thank you @maratal I've made a few comments, let me know what you think?

when (intent.action) {
"io.ably.broadcast.PUSH_ACTIVATE" -> {
val error = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
intent.getParcelableExtra("error", ErrorInfo::class.java)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be wrong here (@ttypic would correct if so), but does the Java SDK actually have ErrorInfo implementing Parcelable?

I think the SDK uses IntentUtils to serialize errors as individual extras.

// ...
val error = IntentUtils.getErrorInfo(intent)```

If I'm right here, wouldn't need `TIRAMISU` version check, or the `@Suppress("DEPRECATION")` block.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, switched to IntentUtils.getErrorInfo(intent).

val channel = realtime.channels.get(channelName)
channel.subscribe { message ->
runOnUiThread {
appendToLog("Received message: ${message.name} - ${message.data}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the user is running the app while adding this code, it will fail to compile.
We should either make step 2 self contained or note that it won't compile until step 4.

So either, create an appendToLog() here, remove it until step 4, or note.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed — updated the Step 3 snippet to use Log.d instead, since appendToLog isn't defined until Step 4.

Log.e(TAG, "Push activation failed: ${error.message}")
updateStatus("Push activation failed: ${error.message}")
} else {
val deviceId = realtime.device().id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

device() can throw errors I think, should we wrap this in a try/catch?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, wrapped in a try/catch.

import io.ably.lib.types.AblyException
import io.ably.lib.types.ErrorInfo
import io.ably.lib.realtime.CompletionListener
import com.google.gson.JsonObject
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this step we add a handful of imports that aren't used until step 5. This is fine, however in step 4 we miss some imports.
ScrollView, Button, Bundle, TextView.

I'd recommend we add them here too.

But we add a note to say something like The following imports cover all steps in this guide What do you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added all missing imports with a note that they cover all steps in this guide.

return instance ?: synchronized(this) {
instance ?: run {
val options = ClientOptions().apply {
key = "{{API_KEY}}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We really should have a comment somewhere to say

// Use token authentication in production

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

</Code>

Sending push notifications using `deviceId` or `clientId` requires the `push-admin` capability for your API key. Use this method for testing purposes.
In a production environment, you would typically send push notifications from your backend server (by posting messages with `push` `extras` field to a channel).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may need to resolve some inconsistencies here.

Throughout the guide we use push and push notifications.

Should we pick with one and stick with it?

For example:

Line 395: "Sending push notifications using deviceId..."
Line 398: "send a push to your client ID"
Line 660: "test pushes via channel"
Line 676: "you don't need the admin capabilities"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, standardised on 'push notifications' throughout.

```
</Code>

Now add push activation and deactivation to your `MainActivity.kt`. The Ably Android SDK sends activation results as local broadcasts, so register a `BroadcastReceiver` to handle them:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we explain here why this pattern is being used? something like: the SDK activates asynchronously and the result arrives via Android's broadcast system)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, added an explanation.


1. [Sign up](https://ably.com/signup) for an Ably account.
2. Create a [new app](https://ably.com/accounts/any/apps/new), and create your first API key in the **API Keys** tab of the dashboard.
3. Your API key will need the `publish` and `subscribe` capabilities. For sending push notifications from your app, you'll also need the `push-admin` capability.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
3. Your API key will need the `publish` and `subscribe` capabilities. For sending push notifications from your app, you'll also need the `push-admin` capability.
3. Your API key needs the `publish` and `subscribe` capabilities. For sending push notifications from your app, you'll also need the `push-admin` capability.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

3. Your API key will need the `publish` and `subscribe` capabilities. For sending push notifications from your app, you'll also need the `push-admin` capability.
4. For channel-based push, add a rule for the channel with **Push notifications enabled** checked. In the dashboard left sidebar: **Configuration** → **Rules** → **Add** or **Edit** a rule, then enable the Push notifications option. See [channel rules](https://ably.com/docs/channels#rules) for details.
5. Install [Android Studio](https://developer.android.com/studio).
6. A real Android device or an emulator with Google Play Services installed (required for FCM).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All other prerequisites start with verbs. This one is a noun. I think we should align it with the others. It's only a small nitpick though.

Suggested change
6. A real Android device or an emulator with Google Play Services installed (required for FCM).
6. Use a real Android device or an emulator with Google Play Services installed (required for FCM).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

1. [Sign up](https://ably.com/signup) for an Ably account.
2. Create a [new app](https://ably.com/accounts/any/apps/new), and create your first API key in the **API Keys** tab of the dashboard.
3. Your API key will need the `publish` and `subscribe` capabilities. For sending push notifications from your app, you'll also need the `push-admin` capability.
4. For channel-based push, add a rule for the channel with **Push notifications enabled** checked. In the dashboard left sidebar: **Configuration** → **Rules** → **Add** or **Edit** a rule, then enable the Push notifications option. See [channel rules](https://ably.com/docs/channels#rules) for details.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
4. For channel-based push, add a rule for the channel with **Push notifications enabled** checked. In the dashboard left sidebar: **Configuration****Rules****Add** or **Edit** a rule, then enable the Push notifications option. See [channel rules](https://ably.com/docs/channels#rules) for details.
4. For channel-based push, add a rule for the channel with **Push notifications enabled** checked. In the dashboard left sidebar: **Configuration****Rules****Add** or **Edit** a rule, then enable the Push notifications option. See [channel rules](/docs/channels#rules) for details.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@maratal maratal force-pushed the DX-287-web-push-guide branch from 94ce859 to 632708e Compare February 26, 2026 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review-app Create a Heroku review app

Development

Successfully merging this pull request may close these issues.

3 participants