38

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.

Akhil Jain
  • 13,872
  • 15
  • 57
  • 93
Sudipta Som
  • 6,537
  • 9
  • 43
  • 67

9 Answers9

47

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
Oussema Aroua
  • 5,225
  • 1
  • 24
  • 44
Felix
  • 88,392
  • 43
  • 149
  • 167
  • 4
    i got mkdir failed for /sdcard/photos, Read-only file system @Felix – Pratik Butani May 30 '13 at 07:45
  • 2
    you might need to set write permissions too. adb shell , mount -o rw,remount rootfs / , chmod 777 /mnt/sdcard , exit then try to copy the image adb push mypic.jpg /sdcard/Pictures – Amalka Mar 01 '15 at 16:52
45

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.

Telmo Pimentel Mota
  • 4,033
  • 16
  • 22
Felby
  • 4,045
  • 4
  • 26
  • 23
20

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.

enter image description here

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.

hcpl
  • 17,382
  • 7
  • 72
  • 73
4

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.

NoNaMe
  • 6,020
  • 30
  • 82
  • 110
3

I can put images in my SD Card in this way:

  1. disconect my phone from USB

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

  3. close the emulator and run again

  4. I check in Eclipse -> DDMS -> File Explorer tab, and I see the image inside storage/sdcard folder

Community
  • 1
  • 1
Hernaldo Gonzalez
  • 1,977
  • 1
  • 21
  • 32
1

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

sundhar
  • 21
  • 1
1

I used this one, it worked for me adb push "C:/image.jpg" /mnt/sdcard/DCIM

then run Media provider (in developer tools) :)

  • What is "Media provider (in the developer tools)" referring to? I don't see anything like that in "platform-tools". – Michael Feb 08 '22 at 03:53
1

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

Amalka
  • 91
  • 1
1

Still annoying, here's some instructions:

  1. Copy files to emulator using adb
adb push MyPictures/* /sdcard/Pictures
  1. 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/"
Ben Winding
  • 10,208
  • 4
  • 80
  • 67
  • 1
    I think you should run this broadcast command on every **file** under the folder, the command don't handle the files recursively – DavidDr90 Mar 03 '22 at 13:07