Pasting text into Android emulator clipboard using adb shell

15

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!

android
emulation
clipboard
copy-paste
asked on Stack Overflow Sep 2, 2011 by Raptorion • edited Sep 2, 2011 by Raptorion

6 Answers

6

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.

answered on Stack Overflow Sep 28, 2011 by Jeonghwan
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

answered on Stack Overflow Aug 5, 2012 by Same old guy...
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...

answered on Stack Overflow Dec 16, 2011 by Cando Zhou
0

Try this:

i32: Write the integer INT into the send parcel.

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

answered on Stack Overflow Jun 4, 2012 by Mat • edited Oct 21, 2012 by Anup Cowkur
0

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

Here is a solution.

answered on Stack Overflow May 20, 2015 by Eddy • edited May 23, 2017 by Community
0

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.

answered on Stack Overflow May 25, 2017 by RoundSparrow hilltx

User contributions licensed under CC BY-SA 3.0