18

I need to paste text into the Android emulator clipboard using adb shell. tried on Android 1.6 and 2.3.1

I tried to use adb shell command: clipboard:[android.text.iclipboard]

"service call clipboard" where service codes are 1, 2, and 3, for getClipboardText, setClipboardText, and hasClipboardText respectively.

service call clipboard 2 s16 thisisinsertedtext 

does not seem to work while

service call clipboard 1 

shows the content of clipboard:

service call clipboard 1
Result: Parcel(
   0x00000000: 00000000 00000001 00000001 00000004 '................'
   0x00000010: 00650074 00740078 00000000          't.e.x.t.....    ')

Please advise how to set a value for emulator clipboard!

Raptorion
  • 181
  • 1
  • 1
  • 5

6 Answers6

5

Looks like all 3 old methods are deprecated since API Level 11 so it won’t work for ICS
Not clear if it's even possible to make it work with service call clipboard anymore...

static final int    TRANSACTION_getClipboardText 1
static final int    TRANSACTION_hasClipboardText 3
static final int    TRANSACTION_setClipboardText 2

www.androidjavadoc.com/1.0_r1_src/constant-values.html
http://developer.android.com/reference/android/content/ClipboardManager.html
http://developer.android.com/guide/topics/text/copy-paste.html

Same old guy...
  • 305
  • 1
  • 3
  • 15
5

Use below command.

service call clipboard 2 i32 1 i32 18 s16 thisisinsertedtext

I think that the first one, "i32 1" is how many elements in clipboard. So, just one. Second is a length of string. The command written above shows...

Result: Parcel(00000000 '....') This usually means OK, no error.

So, my question is, is there any way to copy unicode string? I mean, muti-byte character sets, like Korean. I tried many way, but it failed.

Jeonghwan
  • 59
  • 1
  • How can I paste into clipboard 4 worlds? this is inserted text – Raptorion Oct 28 '11 at 01:15
  • I assume you would put the string in quotes. – David M. Karr May 09 '12 at 19:17
  • 4
    This command line works for my Gingerbread emulator, but not for ICS. The data in the parcel that gets returned says "Unknown package". – David M. Karr May 09 '12 at 19:18
  • 1
    The first i32 is `0` to clear the clipboard, non-zero to set. The code uses ` if ((0!=data.readInt())) ...`. The other i32s encode the spans (i.e. bold) in the text. See the class com.android.server.ClipboardService. – yingted Aug 06 '12 at 17:56
1

adb shell service call clipboard 2 i32 1 i32 1 s16 "你好吗"

Result: Parcel(00000000 '....')

That is OK.

"你好吗" is Chinese character.

The second 'i32 1' can be any integer, maybe...

Community
  • 1
  • 1
Dio Chou
  • 653
  • 5
  • 4
-1

Try this:

i32: Write the integer INT into the send parcel.

s16: Write the UTF-16 string STR into the send parcel.

Anup Cowkur
  • 20,443
  • 6
  • 51
  • 84
Mat
  • 1
-1

Using adb shell command directly do not work since API Level 11.

Here is a solution.

Community
  • 1
  • 1
Eddy
  • 3,623
  • 37
  • 44
-1

There is an open source python script that can deal with the severe limitations: https://github.com/gcb/AdbPaste - and it works well enough except for long clipboard file uploads it's incredibly slow (200 line text file can take 20 minutes).

I found some code on GitHub for an app called clipper that can use adb to populate clipboard via a broadcast intent. I enhanced it to read from a file, the enhanced code is here: https://github.com/RoundSparrow/clipper

Build the app, install on the device. Now I can use ADB commands to populate the clipboard via a file. Works like a charm for a 3 page script I need to upload. Essentially you use like this:

adb push clipboard_content_file.txt /sdcard/clipboard_content_file.txt
adb shell am broadcast -a clipper.setfile -e filepath \'/sdcard/clipboard_content_file.txt\'

It's much faster AdbPaste, it takes only a second or two regardless of the size of the clipboard content.