[Android] Implement Android clipboard setString by winsvega · Pull Request #3720 · SFML/SFML · GitHub
Skip to content

[Android] Implement Android clipboard setString - #3720

Open
winsvega wants to merge 1 commit into
SFML:masterfrom
winsvega:codex/analyze-sf-keyboard-set-text-issue-on-android
Open

winsvega wants to merge 1 commit into
SFML:masterfrom
winsvega:codex/analyze-sf-keyboard-set-text-issue-on-android

Conversation

@winsvega

Copy link
Copy Markdown

Motivation

  • Replace the previous stub that logged "Clipboard API not implemented for Android" with a working implementation to allow setting the system clipboard from Android.
  • Ensure thread-safety and proper JNI attachment/detachment when invoked from native threads.

Description

  • Added includes for Activity.hpp, jni.h, and <mutex> and implemented ClipboardImpl::setString(const String& text) to interact with the Android Clipboard via JNI.
  • Acquire ActivityStates and lock states.mutex, obtain JavaVM/JNIEnv, and attach the current thread to the JVM when necessary using AttachCurrentThread and DetachCurrentThread.
  • Convert the sf::String to UTF-16, create jstring label and data, obtain CLIPBOARD_SERVICE from android/content/Context, call getSystemService, create a ClipData via ClipData.newPlainText, and call ClipboardManager.setPrimaryClip.
  • Clean up all local JNI references after the call and only detach the thread if it was attached in this function.

Testing

  • Performed an Android build of the project using the standard CI-style build (cmake/NDK/ninja) which completed successfully.
  • Tested in my project locally

Codex Task

@winsvega winsvega changed the title Implement Android clipboard setString [Android] Implement Android clipboard setString May 29, 2026
@winsvega

Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant