Pasting text into Android emulator clipboard using

2019-02-11 22:31发布

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!

6条回答
劫难
2楼-- · 2019-02-11 22:48

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.

查看更多
戒情不戒烟
3楼-- · 2019-02-11 22:51

Try this:

i32: Write the integer INT into the send parcel.

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

查看更多
我只想做你的唯一
4楼-- · 2019-02-11 22:51

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

Here is a solution.

查看更多
贪生不怕死
5楼-- · 2019-02-11 22:57

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...

查看更多
The star\"
6楼-- · 2019-02-11 23:02

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

查看更多
甜甜的少女心
7楼-- · 2019-02-11 23:11

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.

查看更多
登录 后发表回答