470

Is there an easy way to copy/paste (desktop's) clipboard content to EditView on Android Emulator?

(just for the sake to ease development/test)

ankitjaininfo
  • 11,961
  • 7
  • 52
  • 75
  • 4
    **re Joel Beckham-send SMS:** > I usually send the text I want to copy as an sms message > through telnet and then copy the text from the sms message. Instead of using telnet you can use eclipse to simulate an incoming sms in the emulator: In the eclipse android tools (version 17 maybe also in older versions) open the DDMS-Perspective. Under "Emulator control"/"Telephony Actions" you can simulate an incoming sms > Once the emulator receives the message you can copy it and paste > it wherever you like. – k3b Apr 06 '12 at 10:15
  • 4
    For anyone looking at this question now; it's supported natively in Android now - just make sure you are using the latest Android Studio/Emulator as mentioned here: https://stackoverflow.com/a/42678005/207552 – bschandramohan May 30 '17 at 14:19
  • 14
    Long press on the text field, and select Paste – onmyway133 Mar 13 '19 at 12:05
  • @onmyway133 tks, it works – Dee Jul 16 '23 at 19:41

25 Answers25

391

In a terminal, type adb shell input text 'my string here. With some characters escaped like \$ that'

Note that an alternative method for including spaces in the text is to substitute %s for each space character.

Rose Perrone
  • 61,572
  • 58
  • 208
  • 243
  • 39
    If you are on a Mac, you can paste the contents of the clipboard even more easily: `adb shell input text "`pbpaste`"` – lowellk Aug 05 '13 at 17:55
  • 1
    works fine on linux, but anyone knows why windows complain when i have spaces? tried escaping them to no aval. – gcb Aug 27 '13 at 20:30
  • 4
    ended up taking some hours today and wrote a workaround in python for the spaces issues. much easier to end bookmarklets to the stock browser now without having to create a dozen sync accounts. https://github.com/gcb/AdbPaste (written while a waited the emulator to load and a couple online gaming sessions ...!$%# slow emulator) – gcb Aug 28 '13 at 06:16
  • adb stands for Android Debug Bridge (adb), found in /platform-tools/ – Mike R Nov 06 '13 at 19:34
  • Any reason why I can't get it to work with a string that contains spaces? I've tried both single and double quotes. `"Hello World"` only sends `hello` to my avd. – lampwins Nov 25 '13 at 00:43
  • 3
    This doesn't seem to work with some UTF characters - after trying to send `'ლ\(ಠ益ಠლ\)'`, it just says 'Killed' or appears to succeed and nothing is typed, nor do I have anything pasteable in the emulator. The SMS method (I tried from DDMS) doesn't even seem to be working here, it displays as "?(????)" :( – Groxx May 08 '14 at 17:21
  • 2
    I too cannot send strings with spaces; I have to use %s. – Peter Jul 29 '14 at 06:28
  • I created SendToAndroid.bat which contains the following: `adb shell input text '%*'` – Peter Jul 29 '14 at 06:29
  • 2
    @Peter and Rose, is there a way to add a new line? `adb shell input text "This%sis%stext\nDoes%snot%work%here."` prints "This is text\nDoes not work here.". – user47 Nov 30 '15 at 05:28
  • @gcb Convert to answer! – Alex Jun 20 '16 at 11:07
  • 1
    Alias for mac to paste direct from clipboard (I couldn't get @lowellk 's snippet working): `alias adbpaste="pbpaste|sed 's/ /%s/g'|xargs adb shell input text"`. Doesn't handle all special characters but it was good enough for my purposes (pasting email addresses and alphanumeric strings.) – Eliot Jul 07 '16 at 01:30
  • 1
    @Eliot Couldn't get your alias to work, but does when transformed to a function. Thanks! http://stackoverflow.com/a/39814283/2301224 – Baker Oct 02 '16 at 05:59
  • On linux paste text from clipboard `adb shell input text "'"$(xclip -selection c -o)"'"` – Andrey Izman Aug 11 '17 at 20:59
  • how to set up adb on a Mac: https://stackoverflow.com/a/28208121/349169 – Chris Oct 19 '21 at 09:19
222

With v25.3.x of the Android Emulator & x86 Google API Emulator system images API Level 19 (Android 4.4 - Kitkat) and higher, you can simply copy and paste from your desktop with your mouse or keyboard.

This feature was announced with Android Studio 2.3

Copy and Paste with the Android Emulator

Jamal Eason
  • 6,260
  • 2
  • 19
  • 15
  • 42
    As of January 2018 there is a known bug in the current emulator version where this occasionally stops working. As a workaround, click the "..." icon, go to Settings, and toggle the "Enable clipboard sharing" setting off and on. ([Source](https://www.reddit.com/r/androiddev/comments/7kn4c8/quick_boot_the_top_features_in_the_android/drh4ytm/)) – mhsmith Jan 11 '18 at 18:52
  • @mhsmith How do you do that (reset clipboard sharing) from the command line with Android command line tools or via editing the `~/.android/avd/` `.ini` files? – Chloe Jan 15 '18 at 18:53
  • @Chloe Since this problem relates to an already-running emulator, I doubt either of those things would make a difference. – mhsmith Jan 15 '18 at 23:02
  • I just Tried it But not works! in Android Studio 3.1 – Avinash Mar 07 '18 at 05:42
  • 4
    How do you paste on a mac? Pressing Cmd brings up multi-touch. Cmd-V does nothing. – jcollum Mar 08 '18 at 01:37
  • 42
    @jcollum left click and hold on the text field you want to paste into, click 'Paste'. cmd+v won't work, neither would ctrl+v, I imagine. – Liam Dawson Jun 18 '18 at 00:51
  • @mhsmith I don't have the "Enable clipboard sharing" option in Settings – Rod Apr 07 '22 at 11:37
  • @Rod: it's in the emulator settings, not the Android Studio settings. However, I haven't used this workaround for a long time, so I don't know if it's still valid. – mhsmith Apr 07 '22 at 13:50
  • @mhsmith Yep, I'm using the emulator settings indeed. Can't find it there, sadly. :/ – Rod Apr 07 '22 at 13:53
  • 2
    Basically this sometimes just stops working for no good reason. I've tried toggling the "Enable clipboard sharing" and it didn't fix it – 1800 INFORMATION Aug 17 '22 at 22:28
  • 1
    For clarity, this setting has moved. It is now located in Android Studio settings (Preferences > Tools > Emulator) as a checkbox. You can also double-tap shift to search for any action, type "clipboard" and it will be in the list of options. – Sean Beach Dec 14 '22 at 20:22
  • 2
    I did on&off 'Enable clipboard sharing' and even restarted the emulator and also the android studio. It doesn't work. And I found simple workaround. write something in your emulator and copy&paste. And then, paste into your editor. And then copy text from desktop and paste into your emulator. It works perfectly. – c-an Mar 24 '23 at 03:17
104

Just copy from wherever, click and hold on the emulator phone's edit text where you want the text to go (kind of like you would press and hold to paste on an actual phone), the PASTE option will appear, then PASTE.

Wachaga Mwaura
  • 3,310
  • 3
  • 28
  • 31
  • 4
    Thank you! Definitely my favorite answer. With the current version of the emulator, this is very convenient. (The current emulator has a setting in the emulator controls under "Settings" which allows for clipboard sharing.) – albert c braun Apr 05 '18 at 15:47
  • 1
    This is how to paste on Mac, since the command key starts touch gestures by default. – Jim Jun 08 '18 at 22:11
87

I usually send the text I want to copy as an sms message through telnet and then copy the text from the sms message. Here's how:

Connect through telnet:

  • Syntax: telnet localhost <port>
  • Example: telnet localhost 5554

(5554 is the default port. The title bar of the emulator shows the port that is being used, so you can see if it's different).

Send message:

  • Syntax: sms send <senders phone number> <message>
  • Example: sms send 1231231234 This is the message you want to send

(You can just make up the senders phone number)

This works really well for links as the message is automatically converted into a hyperlink which you can click without having to copy / paste it into the browser.

Once the emulator receives the message you can copy it and paste it wherever you like.

Joel Beckham
  • 18,254
  • 3
  • 35
  • 58
  • 3
    you even don't need telnet ... you can send sms from ddms (but ddms need telnet however). But nice idea :) – Tima Dec 12 '11 at 15:05
  • Really nice idea but to be honest: no. Doesn't worth the effort for smaller text o.O – nuala Mar 12 '12 at 13:52
  • 1
    For anyone interested, just created a shell script for doing this: https://gist.github.com/2050770 – Todd Mazierski Mar 16 '12 at 16:10
  • +1 nearly exactly what i was looking for. Note: You can send sms from eclipse. (See my answer below) – k3b Apr 06 '12 at 10:18
  • good tip.The method i of course convoluted and bizzarre (as compared to ctrl+V) but ehi, – Alien Life Form Feb 22 '13 at 14:52
  • 8
    This answer is overkill. use `adb`. See my answer. – Rose Perrone May 17 '13 at 22:30
  • @RosePerrone or Joel, is there a way to copy text *from* the emulator back to the desktop? – karl Jul 01 '13 at 19:09
  • Thank you for your response. I feel it is a better solution when sending links to the device. Rather than copying them into the browser , you can simply click them from the messaging app. – Dick Lucas Jun 20 '14 at 13:26
  • The real, simple answer didn't work for me (2 years passed, though). Yours does! My 2 cents pipelining for Mac/Clipboard/Ascii/Multiline (warning: requires 1+ newline): ```echo sms send 0 `pbpaste | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/\\\\n/g'` | telnet localhost 5554``` – eruve Mar 26 '15 at 15:58
  • 1
    Overkill or not, but it allows pasting text as is, without the need to escape special characters. – dmitry Sep 14 '15 at 16:53
  • what's this `sms` command? my telnet on macos doesn't have it – Dominic Jul 27 '17 at 14:07
  • @DominicTobias I believe the sms command is on the emulator on the other end of your telnet session. Can't quite remember, though, and don't have this setup anymore to test it out. – Joel Beckham Sep 09 '17 at 05:31
51

Not sure if that's useful, but, if you need a long URL from desktop browser to be opened in mobile browser, you can send SMS with that URL and open directly from message app.

enter image description here

TEH EMPRAH
  • 1,828
  • 16
  • 32
42

For Mac users, a MUCH easier way is to do this right in the android emulator:

  • click and hold for a second or two
  • release click
  • the option 'paste' will appear as follow

enter image description here

LMG
  • 1,330
  • 11
  • 21
18

If you are using Android Studio on a Mac, you may need to provide the full path to the adb executable. To find this path, open:

Android Studio > Tools > Android > SDK Manager

Copy the path to the SDK location. The adb executable will be within a platform-tools directory. For me, this was the path:

~/Library/Android/sdk/platform-tools/adb

Now you can run this command:

~/Library/Android/sdk/platform-tools/adb shell input text 'thetextyouwanttopaste'
Andrew
  • 227,796
  • 193
  • 515
  • 708
15

On Linux this will paste text directly from the clipboard

adb shell input text "'$(xclip -selection c -o)'"

Also it very useful to create global keyboard shortkey with this command for example Ctrl+Shift+Super+V

Andrey Izman
  • 1,807
  • 1
  • 24
  • 27
  • I find this usefull everytime the clipboard syncing get error and you cant make the copy paste from Mac/Linux to the Emualtor, but using this command make this work again – 123 superatom Feb 08 '23 at 03:51
9

I got tired of this problem so I just made this alias to handle it:

alias ap="pbpaste | xargs adb shell input text"

Then when you open a new terminal window, typing "ap" will paste whatever is on your clipboard into the emulator's actively selected text field.

Setup

Simply add this to your profile (for most users that's ~/.bash_profile for zsh users that's ~/.zshrc) to make the alias available everywhere. Alternatively, if you're a bash user (the default for MacOS), then you can run the following command in the terminal to set it up for you:

echo "alias ap='pbpaste | xargs adb shell input text'" >> ~/.bash_profile && source ~/.bash_profile
gMale
  • 17,147
  • 17
  • 91
  • 116
  • or `alias ap="adb shell input text \`pbpaste\`"` – gderaco Nov 13 '17 at 13:10
  • am using windows and alias `'alias' is not recognized as an internal or external command, operable program or batch file. ` what to do – shareef Sep 25 '18 at 16:16
  • @shareef This wouldn't work for you anyway because `pbpaste` is macOS specific, but there is probably something similar on Windows. `alias` also might not be available to you depending on the shell you're using. – ThomasW Nov 13 '20 at 02:23
8

Only For API level >= 24

Copy any text from your local machine and then simply run this command

adb shell input keyevent 279

Make sure In Android Emulator Settings the Enable Clipboard Sharing options is enabled

Android
  • 1,420
  • 4
  • 13
  • 23
Rishabh Arya
  • 212
  • 5
  • 10
8

My case was that my emulator pasted something that I copied few days earlier and never pasted the last thing in my current clipboard of my laptop.

To solve that I made my emulator starts from cold boot rather than quick boot.

Mohamed Medhat
  • 761
  • 11
  • 16
7

maybe a little bit tricky, but you could send an sms to the emulator by using the emulator control. then you do not have to retype all the text if it is longer and can copy-paste it in the emulator.

another way: connect to emulator via "telnet localhost PORT" and then use hardware event sending to send a text input event to the emulator (needs to be UTF-8). look at this

mad
  • 3,493
  • 4
  • 23
  • 31
7

You can do this without workarounds too. Just click and hold for a bit in the input field till the paste notification appears and then click on paste. That's it!

nana janashia
  • 129
  • 1
  • 4
6

Made this Windows application that allows users to copy paste to Android emulators or connected devices from a visual interface. https://github.com/Florin-Birgu/Android-Copy-Paste

enter image description here

Florin Birgu
  • 495
  • 7
  • 12
6

An easy way is there

  1. Activate keyboard in emulator.
  2. Click on the place you want to paste and long press (press until you see the word PASTE)
  3. Done.

See original answer: https://www.quora.com/How-do-I-paste-text-from-my-computer-to-Android-emulator

nirojan
  • 159
  • 2
  • 3
5

Just click the left mouse button for 2 or 3 seconds, paste button will be appear. Click the paste button and the test will be copied smoothly.

Toufic
  • 292
  • 3
  • 8
2

Have you looked at C2DM? chrome2phone and fox2phone can send links and clipboard text and automatically copy it on the phone. Also, try using the adb shell. There's a service command (/system/bin/service) which can use services (service call clipboard ...). The transaction codes are 1, 2, and 3, for getClipboardText, setClipboardText, and hasClipboardText respectively.

yingted
  • 9,996
  • 4
  • 23
  • 15
1

Using Visual Studio Emulator, Here's my method.

First Mound a virtual sd card:

  1. Use the Additional Tools (small >> icon) for the emulator and go to the SD Card tab.
  2. Select a folder on your computer to sync with the virtual SD card.
  3. Pull from SD card, which will create a folder structure on the selected folder.

Set up a text file to transfer text:

  1. Use Google Play Store to install a text editor of your choice
  2. Create a text file containing your text on you computer in the download directory of the virtual sd card directory you created before.

Whenever I need to send text to the clip board.

  1. Edit the text file created above.
  2. Go to Additional Tools (small >> icon) and chose Push To SD Card.
  3. Open the text file in the text editor I installed and copy the text to the clip board. (Hold down the mouse when the dialog opens, choose select all and then click the copy icon)

Once set up it pretty easy to repeat. The same method would be applicable to other emulators by you may need to use a different method to push your text file to emulator.

Alexander Higgins
  • 6,765
  • 1
  • 23
  • 41
1

(converting comment discussion to answer)

only solution on windows: https://github.com/gcb/AdbPaste

wrote it in a couple hours to work around this problem. I am now back on 100% linux, so feel free to join it as a contributor or maintainer!

gcb
  • 13,901
  • 7
  • 67
  • 92
  • Thanks for this. Note to others: it's slow for sending multiple lines. I have a 3 page LUA script to upload and this solution takes like 20 minutes from a file source. Google really needs to address this need. I know of an open source Keyboard app that has a telnet interface that would be much faster, but switching the keyboard in/out becomes an extra step. – RoundSparrow hilltx May 24 '17 at 17:00
  • 1
    To solve the speed issue mentioned in my last comment: I found it's far faster to just put a tiny helper app on the device that can take clipboard content from adb broadcast command. This populates the clipboard instead of direct input as AdbPaste does - but I was able to enhance it to read a text file and for my 3 page LUA script it now takes only 1 or 2 seconds to go from adb command to having it in the Android textbox. The app is called clipper and enhanced to read text file is here: https://github.com/RoundSparrow/clipper – RoundSparrow hilltx May 25 '17 at 02:19
1

Write command: adb devices (it will list the device currently connected) Select Textbox where you want to write text. Write command: adb shell input text "Yourtext" (make sure only one device is connected to run this command) Done!

Arpan24x7
  • 648
  • 5
  • 24
0

For Mac and Linux try this function in your aliases_bash file (located in /etc/aliases_bash for Mac folks, be sure to use sudo vim /etc/aliases_bash)

function adbtx {
  userinput="$(sed 's/ /%s/g' <<< $1)"
  adb shell input text "${userinput}";
}
export -f adbtx

Then in the command line enter:

adbtx 'Your text to emulator input'

'Your text to emulator input' will be input on the emulator text field.

Kudos to Eliot for his substitution string for sed.

Baker
  • 24,730
  • 11
  • 100
  • 106
0

I came here looking for a solution to the same problem, and ended up writing an Android application to solve this problem. You can download it at http://www.box.net/shared/6203bn441bfltkimajmk. Just give a URL via Preferences menu to point to a place where you can change the Web response easily. The first line of the Web response will be copied to your emulator's clipboard for you. More details can be found at http://agilesc.barryku.com/?p=255.

barryku
  • 2,496
  • 25
  • 16
0

Actually, in my case restarting the MacBook and running the emulator with this command fixed the issue:

 emulator -avd Pixel_5_API_31  -wipe-data

remember that you should use your emulator device, to see the emulator list use this command:

emulator -list-avds 
Ahmad Khani
  • 850
  • 2
  • 10
  • 15
0

Sometimes the clipboard of the emulator is not synched with the system clipboard. It is a bug.

But you can consider the ability to change the value of a variable in debug mode: https://www.jetbrains.com/help/idea/tutorial-set-value.html#solution (Android Studio based on IntelliJ IDEA, so I hope that this link will be helpful)

If your app reads the text from clipboard, you can change the value of the variable for this text and past your text there

0

To my understanding, It's totally depends on the Emulator that you use

Gimnath
  • 824
  • 9
  • 11