Home > Net >  Is there a way to copy text from device to computer when debugging in IntelliJ?
Is there a way to copy text from device to computer when debugging in IntelliJ?

Time:08-04

Is there any convenient way to copy text to the computer from an Android app when running the app in debug mode from IntelliJ?

To be clear, I want to add a button in my app that when tapped copies a string from the app, running on a physical device attached by USB, to the clipboard of the computer that's running the app in debug mode in IntelliJ.

Of course I could log the string, but it's a huge JSON string and I am too lazy to select the string and copy it manually from the log output dozens of times per day (and potentially have to remove hundreds of line breaks each time).

When running on an emulator, it's easy because the emulator and host computer can share the same clipboard. Can something similar be achieved when running on a real device?

CodePudding user response:

On you host (assuming you have netcat and pbcopy available, if not install them or search for replacements):

adb reverse tcp:1234 tcp:1234
nc -l 1234 | pbcopy

then, on your device

echo 'hello clipboard' | nc localhost 1234

once executed your host's clipboard contains

hello clipboard

you can do this from your app as well.

CodePudding user response:

  1. Paste the json to google doc
  2. Open the google doc link in desktop
  • Related