开发者

Pasting text into Android emulator clipboard using adb shell

开发者 https://www.devze.com 2023-04-01 19:38 出处:网络
I need to paste text into the Android emulator clipboard using adb shell. tried on Android 1.6 and 2.3.1

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 thisisinserte开发者_如何转开发dtext 

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!


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.


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


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


Try this:

i32: Write the integer INT into the send parcel.

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


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

Here is a solution.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号