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)
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.
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
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.
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.
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.
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
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'
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
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
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!
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
An easy way is there
Activate keyboard in emulator.
Click on the place you want to paste and long press (press until you see the word PASTE)
Done.
See original answer: https://www.quora.com/How-do-I-paste-text-from-my-computer-to-Android-emulator
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
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
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.
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.
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.
Using Visual Studio Emulator, Here's my method.
First Mound a virtual sd card:
Use the Additional Tools (small >> icon) for the emulator and go to
the SD Card tab.
Select a folder on your computer to sync with the
virtual SD card.
Pull from SD card, which will create a folder structure on the selected folder.
Set up a text file to transfer text:
Use Google Play Store to install a text editor of your choice
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.
Edit the text file created above.
Go to Additional Tools (small >> icon) and chose Push To SD Card.
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.
(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!
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!
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.
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.
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
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
Related
So I am trying to disable keyboard suggestions and contact suggestions programmatically on an aosp api 29 emulator (for e2e screenshot test purposes) which I belive should start like adb shell settings put ... but I cannot seem to find a command to switch that off as my google fu is not strong enough. Would be amazing if someone here knows the answer to that.
So what I would like to achieve is to disable the suggestion part in the image shown below
Thank you in advance
If you are using AVD from android SDK, in wizard configuration there is show advance settings that let you enable keyboard input or not.
And if you are using another emulator apps there should be an address like ~/.android/avd/<The_Device_Name>/config.ini in your home directory and then Change the below setting to be:
hw.keyboard=yes
also do not forget to restart the emulator after changes.
I am setting up a CI server which creates Android AVDs on the fly to run automated UI tests. This works great, but since the CI gets brand new emulators with brand new images each time a job is run, I get all of the Android welcome and first run and do you agree prompts. These break my tests.
Is there anyway to have the emulator auto-accept or dismiss all of these prompts?
Here are some examples:
After much digging and experimentation, I've figured out a way to work around both of the prompts mentioned above. There isn't a catch-all solution, but here it goes, piece by piece.
Chrome
Before starting up Chrome for the first time, run this command with adb:
./adb shell 'echo "chrome --disable-fre --no-default-browser-check --no-first-run" > /data/local/tmp/chrome-command-line'
Basically, this writes out a file to a known location which Chrome will check on boot. All of the flags specified in the command are obeyed, and those inheriently disable all of the first run prompts. This link was very helpful.
Keyboard (Gboard)
The Android shell has a tool called ime to manage the input methods available on the device. By default, on newer devices in English, the input method is LatinIME. This is the Latin implementation of Gboard, which provided the legal prompt shown above.
The easiest solution is to select another keyboard which doesn't have this prompt. I used the old SoftKeyboard:
./adb shell 'ime set com.example.android.softkeyboard/.SoftKeyboard'
You may obtain a list of available keyboards, like so:
./adb shell 'ime list -a -s'
Final Result
I've set up Android on a virtualbox, it boots and runs correctly.
However I'm trying to start its console so I can do netcfg and get the IP address, so I can try connecting the adb to it.
As the tutorials say, I tried pressing ALT + F1 but it has no effect. I've tried both the right and left ALT buttons but the console doesn't show up.
What am I doing wrong? Does Android have to be started in Debug mode to see the console?
No need for Debug mode for use the console. What a image are you use? Try [Ctrl]+Alt+F2/F3, or download other image.
Easiest way it's to open the Android Apps inside the VM and open a Terminal Emulator like you will do in your phone.
At least, I do it that way as ALT+F1 doesn't work for me.
Then, in the terminal emulator, you can use "su" to root and "netcfg" to know the IP of the VM so as to use it in "adb connect IP".
Hope it helps
I want to add picture in emulator's gallery. But i am not able to do this. How to do this? any clue! Though i have gone through a answer posted in stack over flow but didn't get success with that answer.
Check this Once you have a virtual SD card in your emulator, if you're not comfortable with mtools or if you don't know how to mount a loopback device on Linux (which is really easy by the way), just use adb push to upload your images. Possible example:
adb shell mkdir /sdcard/Pictures
adb push mypic.jpg /sdcard/Pictures
You can also use the DDMS tool in eclipse to push or pull a file onto the emulator. On a 2.2 emulator I was able to push some .jpg images into the /mnt/sdcard/DCIM/100ANDRO folder using DDMS. I then had to go into the running emulator itself, select "Dev Tools" from the Apps screen, the select "Media Scanner" (or "Media Provider" in newer versions of Android) to get the emulator to recognize the files so they would be displayed in the Media Gallery.
First thing to do is to get the image(s) at the storage of the emulator. For this you have several options. I'll list the most common options here. But first an important note on the need to scan for this media on the emulator. As pointed out by Felby in another answer.
Where to put the images
The standard location (for the devices I've tested so far) where images from the camera are put on the device is /mnt/sdcard/DCIM/100ANDRO.
However since we need to scan manually anyway you can put them at /mnt/sdcard/Pictures or any other valid path on the (emulated) sdcard.
The /sdcard/ path is linked to /mnt/sdcard/ so that will also work. I'm just mentioning this because I've seen this path on another answer.
How to upload images to emulator
Using adb
For hardcore users, execute the adb push from command line. If you don't know how to work with adb I can recommend reading up on this help article. Make sure you have the path set correctly for your system and adb devices returns at least one device (if more specify device in command).
adb push /path/to/image.jpg /mnt/sdcard/DCIM/100ANDRO
Using eclipse (ADT)
You can achieve the same by clicking some buttons in ADT. Go to the DDMS perspective and in the file explorer select the icon on the top. Check image below for details.
image linked from http://cdn.cybersectors.com/
Scan for media
An important step not to forget is executing this tool on the Android Emulator. If you skip this the Gallery will remain empty. Many thanks to Felby for pointing this out.
I then had to go into the running emulator itself, select "Dev Tools" from the Apps screen,
the select "Media Scanner" (or "Media Provider" in newer versions of
Android) to get the emulator to recognize the files so they would be
displayed in the Media Gallery.
If you need any of the image then simply go to google.com from the browser of your emulator and search for the images as you like and click on the image. when it is opened select full size option of the image and then press and hold the mouse for some seconds, this will give you saving options. you may search the options into the context menu as well.
Hope this will help some-one.
I can put images in my SD Card in this way:
disconect my phone from USB
using adb push command line with the folder storage/sdcard and not /sdcard, example
D:\adt-bundle-windows-x86-20131030\sdk\platform-tools>adb push "d:\star.jpg" storage/sdcard
close the emulator and run again
I check in Eclipse -> DDMS -> File Explorer tab, and I see the image inside storage/sdcard folder
scanning for media might stop the developer tools sometimes... if so push the files into storage/sdcard/DCIM folder using DDMS mode as mentioned in the picture above and just restart the emulator....
I used this one, it worked for me
adb push "C:/image.jpg" /mnt/sdcard/DCIM
then run Media provider (in developer tools)
:)
you might need to set write permissions too.
adb shell
mkdir /sdcard/Pictures
mount -o rw,remount rootfs /
chmod 777 /mnt/sdcard
exit
then try to copy the image
adb push mypic.jpg /sdcard/Pictures
Still annoying, here's some instructions:
Copy files to emulator using adb
adb push MyPictures/* /sdcard/Pictures
Reboot device, which lets Android to check system for new media files
adb reboot
Then the files should show up! Super annoying to reboot, but that's the most reliable method I could find.
Note:
This scripts is meant to refresh the media gallery, but I couldn't get it to work:
adb shell "am broadcast -a android.intent.action.MEDIA_SCANNER_SCAN_FILE -d file:///sdcard/Pictures/"
I develop all my sites on a OS 10.5.8 server with PHP and MySQL, and I've configured my /etc/hosts and httpd.conf files to display my site at example.dev in any browser on that machine.
I recently installed Android's software development kit which I'd like to use to develop and test stylesheets targeted to mobile Webkit-- but I can't access my locally-hosted projects in the Android browser.
This makes sense, since it's emulating the whole Android OS, but is there a workaround? Or can I only test projects that exist somewhere on the actual computer internet, perhaps in a hidden directory?
Someone suggested that I edit my /etc/resolv.conf file, but I don't know the correct way to format a locally-hosted domain in the resolv.conf-- I tried variations of the following, and nothing works:
domain example.dev
nameserver 127.0.0.1
Or...
domain example.dev
nameserver localhost
In my hosts file, it is set up like this:
127.0.0.1 localhost example.dev example2.dev [etc]
You should be able to use the IP address of your mac in the URL from the android emulator and be able to access your sites that way. Of course, make sure that Web Sharing is turned on under Sharing in System Preferences, and that your firewall isn't blocking the address.
Alternately, you can use the virtual host IP address, which is 10.0.2.2. This will always map to your host mac when running the emulator.
If for some reason you prefer not to use IP addresses in your urls, you can map your mac's IP address to any name you choose by modifying /etc/hosts in your emulator. To do so, you'll need to first make the filesystem read-write, then add your mac's IP and whatever hostname you want to /etc/hosts:
adb -e shell
# mount -o remount,rw -t yaffs2 /dev/block/mtdblock0 /system
# echo '10.0.2.2 cat-yodeling.local' >> /etc/hosts
Then access "http://cat-yodeling.local" from your browser. You should be good to go.
I was having this same issue. #emmby's solution sounded like it should do exactly what I needed, but strangely it didn't seem to work. The commands ran, but looking at the hosts file afterward showed that it wasn't actually being updated.
But I did a bit more research, and I've worked out what the problem was.
The core issue I was having was that the emulated device's operating system was already taking up 100% of available storage, so the edits were not getting written to the hosts file. However there was no error message being given either.
My guess is that the reason #emmby didn't have this problem is because the issue varies depending on the version of Android that you put on the emulator; some versions may give you some free space to work with.
If you do have this problem, the solution to this is to start the emulator with more storage. This can be done with the -partition-size argument for the emulator command, like so:
emulator -partition-size 128 #MyEmulatedDevice
You can then use the adb -e shell command and edit the file as per #emmby's answer.
However, if editing the file from the shell is a pain, adb does also give you the facility to copy it down from the emulator to your host OS, edit it locally, and copy it back up again. It also deals with the remount. You would do it like this:
adb pull /system/etc/hosts C:\wherever\you\want\to\save\it
Then edit it in your favourite editor.
Then remount the emulator to read/write mode, and copy the file back:
adb remount
adb push C:\wherever\you\saved\hosts /system/etc/hosts
Note that since the emulator is reset back to default state whenever you restart it, this might be a better solution, because you can keep the edited file locally, so you don't have to repeat the adb pull and editing steps every time; you can simply start the emulator, do the remount and push, and you're in business.
Hope that helps.
I worked around similar issue by using computers IP address in local network.
Follow the instructions on the following two links:
http://www.codingonstilts.com/2012/04/android-emulator-hosts-file-entry.html (make sure to pay attention to the tabs between the IP address and the hostname and the newline at the bottom of the file)
I did a "[SDKLOCATION]/platform-tools/adb pull /system/etc/hosts WHATEVERHOSTFILENAME" to see the format of the original hostfile first and then use that to push it back.
And then:
http://www.codingonstilts.com/2012/06/sync-os-x-hosts-file-to-android.html
Works for me - good luck!!
As per android docs you can access your system 127.0.0.1 IP using 10.0.2.2 on your emulator which is a special alias to your host loopback interface.