Push Notification

You can integrate Channel Talk 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 {
	// A core module
	implementation 'io.channel:plugin-android:$[version]'

	// Used to setup FCM easily
	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

Channel supports two ways to integrate with Firebase: Firebase Cloud Messaging API(V1) and Cloud Messaging API(Legacy).

Firebase Cloud Messaging API(V1)

  1. Navigate to Project Overview > Project settings.
  1. Navigate to Cloud Messaging tab and click Manage Service Accounts.
  1. Prior to creating a service account, create a role. Navigate to Roles.
  1. Click CREATE ROLE.
  1. Fill in details and click ADD PERMISSIONS.
  1. Create a role with cloudmessaging.messages.create permission. You can find it by keyword using filter. Make sure you are typing keywords to "Enter property name or value" field NOT "Filter permissions by role."
  1. Navigate back to service accounts page and click CREATE SERVICE ACCOUNT.
  1. Fill in details and click CREATE AND CONTINUE.
  1. Click Select a role.
  1. Select a role created at step 6.
  1. Navigate to Manage keys for the service account.
  1. Create a key by ADD KEY > Create new key with JSON format.
  1. Upload the key file to Channel Desk at Channel Settings > Security and Development > Mobile SDK Push > Android.

Cloud Messaging API(Legacy)

  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.
  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