Skip to content

[rcore] adding copy to clipboard on android - #6404

Merged
raysan5 merged 2 commits into
raysan5:masterfrom
emecdelam:master
Nov 13, 2026
Merged

raysan5 merged 2 commits into
raysan5:masterfrom
emecdelam:master

Conversation

@emecdelam

@emecdelam emecdelam commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

This pr implements SetClipboardText in rcore_android.c

The code uses the same structure as the OpenURL implementation

Hereunder a demonstration, also tested on an actual smartphone (Android 12)

cropped-1360x990-2026-11-11.20-53-23.mp4

with the following test code

#include "raylib.h"

int main()
{
    InitWindow(800, 400, "Test");
    SetTargetFPS(60);

    while (!WindowShouldClose())
    {
        Rectangle button = { (float)GetScreenWidth() / 2.0f - 50, (float)GetScreenHeight()/ 2.0f - 30, 100, 60 };

        bool hovered = CheckCollisionPointRec(GetMousePosition(), button);

// ======================
        if (hovered && IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
            SetClipboardText("Testtestst");
        }
// ======================
        const char* currentClipboard = GetClipboardText();
        if (currentClipboard == 0) currentClipboard = "None";

        BeginDrawing();
            ClearBackground(RAYWHITE);

            DrawRectangleRec(button, hovered ? SKYBLUE : LIGHTGRAY);
            DrawRectangleLinesEx(button, 2, DARKGRAY);

            int textWidth = MeasureText("Click me", 20);
            DrawText("Click me", button.x + (button.width - textWidth)/2, button.y + 20, 20, BLACK);
            
            DrawText(TextFormat("Clipboard : %s", currentClipboard), 20, 20, 20, BLACK);

        EndDrawing();
    }

    CloseWindow();
    return 0;
}

Note : this is my first time using JNI and I would like to have an experienced maintainer with android tell me if I forgot some memory deallocation, I think everything is taken care of when detaching the thread like the OpenURL implementation.

@raysan5

raysan5 commented Nov 11, 2026

Copy link
Copy Markdown
Owner

@emecdelam thanks but solution should be through ndk, not jni...

@emecdelam

emecdelam commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor Author

@raysan5 I didn't find any reference in the NDK (https://developer.android.com/ndk/reference) to any clipboard support, I'm not sure what you mean by using the ndk, as far as I'm aware the only way in C to have access to clipboard is trough the JNI

@raysan5

raysan5 commented Nov 13, 2026

Copy link
Copy Markdown
Owner

@emecdelam Oh, you are right, no clipboard exposed by NDK. Ok, merging this solution, thanks!

@raysan5
raysan5 merged commit 3c3ffbb into raysan5:master Nov 13, 2026
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.

2 participants