Push Notification

You can integrate Channel Android SDK with Firebase Cloud Messaging(FCM) to deliver push notifications when a manager replies to a message. Complete installing the SDK before following these steps.

📘

To use system push notification in Android API level 33(Tiramisu) or above, you need POST_NOTIFICATIONS permission.

Channel Android SDK does not request permission. Your application should request it manually. See Android official documentation regarding notification.

Firebase integration

Setting up a Firebase project

  1. Configure Android project with Firebase setup guide.
  2. Download the google-service.json file and place it in the root directory of the app scope module.

Integrating Firebase with SDK

Follow one of the two sections based on whether your project has Firebase imported.

If your project was not using Firebase

You can add the following dependency, which integrates with the FCM automatically. The dependency will automatically handle Firebase messages.
Maven Central

// app/build.gradle
dependencies {
    implementation 'io.channel:plugin-android-fcm:$[version]'
}

If your project was already using Firebase

You should forward some information to the SDK to process push notifications using ChannelIO.receivePushNotification().

class SampleFirebaseMessagingService : FirebaseMessagingService() {
    override fun onNewToken(refreshedToken: String) {
        ChannelIO.initPushToken(refreshedToken)
        // ...
    }

    override fun onMessageReceived(remoteMessage: RemoteMessage) {
        val pushMessage = remoteMessage.data

        if (ChannelIO.isChannelPushNotification(pushMessage)) {
            ChannelIO.receivePushNotification(application, pushMessage)
        } else {
            // ...
        }
    }
}

📘

If FCM is already installed on your project, onNewToken might not be called. In this case, push notifications will not be received. Reinstalling the application will fix the issue.

In your app’s launcher activity, call openStoredPushNotification to launch the associated chat with the notification.

class SampleActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        if (ChannelIO.hasStoredPushNotification(this)) {
            ChannelIO.openStoredPushNotification(this);
        }
    }
}

📘

Any notification-related information stored in the SDK is removed during boot. You should call openStoredPushNotification before your SDK completes the boot.

Integrate Firebase with Channel Desk

  1. Go to Project Overview > Project Settings which can be found in the sidebar on the left.
  2. Navigate to the Cloud Messaging tab. Copy the Server key from the Cloud Messaging API (Legacy) section.
1033
  1. Go to Channel Settings > Security and Development > Mobile SDK Push > Android.
1253
  1. Paste the Server key copied in Step 2.

Customizing push notification

Changing a push title

You can set the title of a push notification by changing the value of notification_title in strings.xml. The default value is the app’s name.

<resources>
  <string name="notification_title">Your notification title</string>
</resources>

Changing a push icon

If you wish to change the push icon, place the image file on the following path:

/res/drawable/ch_push_icon.png