Channel Developers

Using JavaScript SDK within the Android WebView requires some extra steps.

JavaScript SDK does not provide a push notification.

Use Android SDK instead of the JavaScript SDK to support a push notification. See the instructions of Android(SDK) section to follow the best practices.

To allow new tab in an Android WebView, some additional configurations are required.

Kotlin

If you are using Android WebView, users will not be able to launch a file chooser when they click the attachment button to send files. The problem is that WebView does not implement default file choosing behavior, so we must manually define how we handle the users' actions. With our simple solution and snippets, you will only take a minimal effort on integrating JavaScript SDK with your mobile application.

We highly recommend using the Android SDK for those who are looking for effortless and straightforward experiences on mobile devices.

  1. Allow WebView to access files and set WebChromeClient to get notified when the user wants to open the file chooser.

Kotlin
  1. Copy our code of WebViewAttachmentModule class that is responsible for handling file chooser callbacks. Note that you may change the snippet as it is provided to help you write code faster.

Make sure to return true from onShowFileChooser

The WebChromeClient does not allow filePathCallback to be invoked if onShowFileChooser returns false. As the module always calls the callback when an intent for a file chooser is created, make sure to call getIntentChooser only if onShowFileChooser returns true.

Kotlin

Please be aware that Android WebView does not natively support downloading files such as photos or videos. The following code demonstrates how to intercept URL requests and download files when they are identified as images or videos, specifically from Channel Talk.

  1. Refer to the following to write a listener responsible for handling image / video downloads.

Kotlin
  1. Apply the written listener to the activity. An example is shown below.

Kotlin

Please change the following sample code to fit your requirements.

Kotlin

Instead of embedding JavaScript SDK to the WebView, you might decide to use Android SDK along with the WebView. A major reason for the decision is when you need to send a push notification. See how to get started with the Android SDK and enabling the push notification.

Hide redundant Channel SDK UI.

When using both JavaScript SDK and Android SDK, set hideChannelButtonOnBoot and hidePopup=true in Boot Option of JavaScript SDK to hide the Channel button and popups. Android SDK and JavaScript SDK might duplicate Channel SDK UI.

To allow Android SDK to know the current URL of the WebView, call setPage with appropriate data. Event tracking and workflow targeting will work smoothly with the information.

Kotlin

This section describes how to use the JavaScript SDK installed on the mobile web in an iOS WebView environment.

Ensure filled out your info.plist

Before you get started, refer to this After Installation to make sure you've filled out your Info.plist with a description of the permissions you use.

Push Notification doesn’t work if you are using only JavaScript.

To use the push notification, Refers ChannelIO iOS SDK

The Following Example loads a page with a URL in your YOUR_WEB_URL on any WebView ViewController.

Swift

These requirements are already described above. each are marked as #1, #2 and #3.

allowsInlineMediaPlayback is a configuration option for whether HTML5 video plays as inline or as full screen. The default value is false. Therefore, If there is a video in the SDK, It will play as full screen automatically.

To fix this, you should modify the allowsInlineMediaPlayback to true.

All of the link property of the JavaScript SDK is target="_blank". Thus, It will open with a new tap.

However, WKWebView can't handle target="_blank" automatically, you should add this code example to deal with.

This example is If the link action is from target="_blank", retrieve the link from action and load the URL on the WebView.

Please be aware that WKWebView does not natively support downloading files such as photos or videos. The above code demonstrates how to intercept URL requests and download files when they are identified as file, images or videos, specifically from Channel Talk.