Skip to content

Clipboard Protection

Restricting copy and paste functionality may be necessary for applications that handle confidential or sensitive data. This ensures that data does not leave the application through user actions or through a malicious app that reads the clipboard. Even if malware cannot break into an application, it can still read the clipboard content and steal data.

Once clipboard protection is enabled on the server, add the ClipboardProtectionService instance to the SDKInitializer.start method. This ensures that data copied or cut within a protected application cannot be pasted into external applications, and that content from external applications cannot be pasted into the protected application.

The ClipboardProtectionService constructor accepts an optional argument to enable protection before receiving the signal from the server. By default, this feature is disabled.

val services = mutableListOf<MobileService>()
services.add(ClipboardProtectionService(initClipboardProtectionEnabled = true))
SDKInitializer.start(this, * services.toTypedArray())

Currently, clipboard protection supports only text, not images or other formats. For View-Based apps, no additional configuration is required.

Note

Content copied or cut from external apps will still appear in the clipboard history list, allowing users to paste it directly by clicking on it. Currently, there is no way to prevent this behavior.

Additionally, starting with SDK V25.4.0, clipboard protection will not work in View-Based apps on Samsung devices running Android 11 or lower, because users can bypass it via the clipboard history.

Clipboard Protection for Jetpack Compose Based Apps

In a Jetpack Compose environment, in addition to adding the ClipboardProtectionService instance to the SDKInitializer.start method, you must use sdkClipboard provided by ClipboardProtectionService as a localClipboard. Note that sdkClipboardManager has been deprecated since SDK V26.4.0, and LocalClipboardManager is also deprecated. The following example demonstrates how to implement this. Make sure to cast sdkClipboard to androidx.compose.ui.platform.Clipboard first:

setContent {
    FioriHorizonTheme {
        // Make sure you import `androidx.compose.ui.platform.Clipboard`.
        val localClipboard =
                    SDKInitializer.getService(ClipboardProtectionService::class)?.sdkClipboard as? Clipboard
                    ?: LocalClipboard.current
        CompositionLocalProvider(
            LocalClipboard provides localClipboard
        ) {
            // Add your code
        }
    }
}

Note

sdkClipboard is supported only for composable views on Samsung devices running Android 11 or lower. In all other cases, sdkClipboard will be null. Starting with SDK V24.12.0, if your project uses the flows-compose library and the FlowComposeTheme, the localClipboard logic is already included in FlowComposeTheme, so separate implementation is not required.

setContent {
    FlowComposeTheme {
        // Add your code
    }
}

Add the code provided above to the onCreate method. The sdkClipboard will protect any screens contained within the CompositionLocalProvider.

Clipboard Protection for WebView in Compose-Based Apps

For Jetpack Compose-based apps, you need to customize the WebView to enable clipboard protection. For example:

@Composable
fun CustomWebView(url: String) {
    val clipboardProtectionService = SDKInitializer.getService(ClipboardProtectionService::class)
    AndroidView(
        factory = { context ->
            WebView(context).apply {
                // Make sure JavaScript is enabled.
                settings.javaScriptEnabled = true
                webViewClient = object : WebViewClient() {
                    override fun onPageFinished(view: WebView, url: String) {
                        super.onPageFinished(view, url)
                        // Inject JavaScript code supplied by ClipboardProtectionService.
                        clipboardProtectionService?.let {
                            evaluateJavascript(it.getJavaScriptCodeForWebView(), null)
                        }
                    }
                }
                // Make sure the injected JavaScript code above can invoke the functions from ClipboardProtectionService.
                clipboardProtectionService?.let { addJavascriptInterface(it.JsWebInterface(), ClipboardProtectionService.JS_FUNC_ACCESS_NAME) }
                loadUrl(url)
            }
        }
    )
}

The ClipboardProtectionService provides JavaScript code for WebView to support clipboard protection. To add your own JavaScript code, insert it before the "SDK-provided" code and combine them into a single string. Then, pass the combined string to evaluateJavascript in the onPageFinished method.

Note

On Samsung devices running Android 11 or lower, clipboard protection does not work within IFrames in a WebView that is part of a Compose-based app.


Last update: August 19, 2026