Genymobile / Genymobile/scrcpy

OnPrimaryClipChangedListener can't get text in cliboard

Open
#6,366 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
150k
Forks
13.7k
Avg merge
4d 13h
Merged PRs (30d)
2

Description

_Please read the [prerequisites] to run scrcpy._

[prerequisites]: https://github.com/Genymobile/scrcpy#prerequisites

_Also read the [FAQ] and check if your [issue][issues] already exists._

[FAQ]: https://github.com/Genymobile/scrcpy/blob/master/FAQ.md
[issues]: https://github.com/Genymobile/scrcpy/issues

## Environment

- **OS:** macos
- **Scrcpy version:** [3.3.2]
- **Installation method:** [manual build]
- **Device model: *samsung*
- **Android version:** [12]

## Describe the bug

I want to test copying text from the phone and then sending it to my PC through socket, but I found that I can monitor the changes in the clipboard but cannot read the message content.
i just add logs in the addPrimaryClipChangedListener:

```
// Make sure the clipboard manager is always created from the main thread (even if clipboardAutosync is disabled)
ClipboardManager clipboardManager = ServiceManager.getClipboardManager();
if (clipboardAutosync) {
// If control and autosync are enabled, synchronize Android clipboard to the computer automatically
if (clipboardManager != null) {
clipboardManager.addPrimaryClipChangedListener(() -> {
if (isSettingClipboard.get()) {
// This is a notification for the change we are currently applying, ignore it
return;
}
String text = Device.getClipboardText();
Ln.i("clipboard has change");
if (text != null) {
Ln.i("clipboard data is: " + text);
DeviceMessage msg = DeviceMessage.createClipboard(text);
sender.send(msg);
}
});
} else {
Ln.w("No clipboard manager, copy-paste between device and computer will not work");
}
}
```

When I copy text in my phone, the output is as follows:

```
[server] INFO: clipboard has change
[server] INFO: clipboard has change
[server] INFO: clipboard has change
[server] INFO: clipboard has change
[server] INFO: clipboard has change
[server] INFO: clipboard has change
```

the ‘clipboard data is:’ has no output

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.