复制到剪贴板不起作用于Android

发布于 2025-02-10 14:37:58 字数 1469 浏览 3 评论 0原文

使用此视图创建标准移动应用程序:

public class DebugView extends View {

    ListView<String> console = new ListView<>();

    private DebugView() {
        setCenter(console);
        console.getItems().add("A");
        console.getItems().add("A2");
        console.getItems().add("A3");
        console.getItems().add("A4");
        
        var copyButton = new Button("Copy");
        copyButton.setOnAction(e -> {
            String log = console.getItems().stream().collect(Collectors.joining(System.lineSeparator()));
            var content = new ClipboardContent();
            content.putString(log);
            Clipboard.getSystemClipboard().setContent(content);
            var message = new Toast("Copied to clipboard");
            message.show();
        });

        setBottom(copyButton);
    }
}

在桌面上运行它,然后按复制按钮,您可以将内容粘贴到文本编辑器中。

在Android上运行它,然后按复制按钮,您无法将内容粘贴到Gmail等其他应用程序中。您以前的复制内容(如果存在)将被粘贴,因此看来剪贴板上没有任何内容,或者剪贴板不可用。

如何使剪贴板在移动设备上工作?

使用

<javafx-maven-plugin-version>0.0.8</javafx-maven-plugin-version>
<gluonfx-maven-plugin-version>1.0.14</gluonfx-maven-plugin-version>

<java-version>17</java-version>
<javafx-version>18.0.1</javafx-version>
<charm-version>6.1.0</charm-version>
<attach-version>4.0.14-SNAPSHOT</attach-version>

和graalvm-svm-java17-linux-gluon-22.1.0.1-Final

Create a standard mobile application with this view:

public class DebugView extends View {

    ListView<String> console = new ListView<>();

    private DebugView() {
        setCenter(console);
        console.getItems().add("A");
        console.getItems().add("A2");
        console.getItems().add("A3");
        console.getItems().add("A4");
        
        var copyButton = new Button("Copy");
        copyButton.setOnAction(e -> {
            String log = console.getItems().stream().collect(Collectors.joining(System.lineSeparator()));
            var content = new ClipboardContent();
            content.putString(log);
            Clipboard.getSystemClipboard().setContent(content);
            var message = new Toast("Copied to clipboard");
            message.show();
        });

        setBottom(copyButton);
    }
}

Run it on desktop and press the Copy button, you can paste the contents into a text editor.

Run it on Android and press the Copy button, you can't paste the contents into another app, like Gmail. Your previous copied content (if exists) will be pasted, so it appears that nothing is added to the clipboard, or that the clipboard is not available.

How to make Clipboard work on mobile?

Using

<javafx-maven-plugin-version>0.0.8</javafx-maven-plugin-version>
<gluonfx-maven-plugin-version>1.0.14</gluonfx-maven-plugin-version>

<java-version>17</java-version>
<javafx-version>18.0.1</javafx-version>
<charm-version>6.1.0</charm-version>
<attach-version>4.0.14-SNAPSHOT</attach-version>

and graalvm-svm-java17-linux-gluon-22.1.0.1-Final

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

娇柔作态 2025-02-17 14:37:58

附件的版本4.0.14-snapshot不支持Android剪贴板。版本4.0.15-snapshot 添加了功能性代码> 4.0.15 已在此支持下发布。

The version of Attach 4.0.14-SNAPSHOT did not support Android clipboard. Version 4.0.15-SNAPSHOT added the functionality and 4.0.15 has been released with this support.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文