4

I'd like to create an Android Virtual Device against which I can test recent issues with writing to external SD cards. I would expect the external sd card to be found at location like "/storage/extSdCard/DCIM/" on the AVD's file system. Any suggestions on how I can accomplish this?

ab11
  • 19,770
  • 42
  • 120
  • 207
  • I am not aware that the emulator supports this. – CommonsWare Nov 14 '14 at 16:24
  • I'd like to test writing to external storage for both 4.2+ and 5.0. Any idea if this is possible using the emulator? (any idea how to test on 5.0 if it's not possible through the emulator?) – ab11 Nov 14 '14 at 16:53
  • The emulator supports [external storage](http://commonsware.com/blog/2014/04/08/storage-situation-external-storage.html). That has nothing to do with "external SD cards" (i.e., [removable storage](http://commonsware.com/blog/2014/04/09/storage-situation-removable-storage.html)). – CommonsWare Nov 14 '14 at 16:58
  • fair enough. yes, it is removable storage that i'm referring to. so, let's say i want to allow users to write to removable storage. and i'd like my solution to work for all versions. any advice as to what such a solution would look like, and how i could test it? – ab11 Nov 14 '14 at 17:02
  • As noted in the blog post that I linked to in my comment, there is no official support for removable media prior to Android 4.4. – CommonsWare Nov 14 '14 at 17:09
  • That being the case, users aren't very happy that my app no longer can write to their removable storage. And "The OS does not support this functionality" isn't a particularly acceptable answer when competing apps use workarounds to provide the functionality. So, I intend to use a workaround for kit-kat users, and use the new api for future lollipop users. Unfortunately, I'm having difficulty figuring out how to test the various cases? – ab11 Nov 14 '14 at 17:15
  • AFAIK, you will have to test the cases on hardware. – CommonsWare Nov 14 '14 at 17:18

3 Answers3

7

To add removable storage to your AVD use:

 ~/Android/android-sdk/tools/mksdcard [memory size] [output file] 

to create SD card image.

Then pass it in Advanced AVD Settings dialog: SD card -> External file

DONE :)

You can learn more about the mksdcard tool here: https://developer.android.com/studio/command-line/mksdcard

Eric Mutta
  • 1,144
  • 1
  • 11
  • 15
i.shadrin
  • 5,038
  • 2
  • 21
  • 13
  • memory size is what in bytes, Kb, MB or GB? – demosthenes Aug 18 '18 at 04:49
  • If size is a simple integer, it specifies the size in bytes. You can also specify the size in kilobytes, megabytes, and gigabytes by appending K, M, or G to size. For example, 1048576K or 1024M. The minimum size is 9M. The Android emulator cannot use smaller images. The maximum size is 1099511627264 bytes, which equates to 1023 GB. – i.shadrin Sep 17 '18 at 22:39
1

You can open Android Device Monitor which is the Android symbol next to the SDK Manager. Once opened you can see the files using the file explorer and here you can create the required folders/path for using the external SD card.

There is a chance that when you try and create a folder it will say it is read only, if this happens open up command prompt and using adb shell input these commands:

mount -o rw,remount rootfs /
chmod 777 /mnt/sdcard
exit

These commands are from this link

Community
  • 1
  • 1
Zoro
  • 11
  • 3
  • thanks. but i'm not sure what you mean by seeing the files and creating the path using the file explorer. do you mean a file explorer app on the AVD? if so, my AVD doesn't have a file explorer? – ab11 Nov 14 '14 at 16:51
  • follow this: http://stackoverflow.com/a/15515511/2942125 if using android studio it is under tools, android, android device monitor – Zoro Nov 14 '14 at 17:04
0

On macOS Mojave 1.14.3 with Android Studio 3.3.1 I found the path to be slightly different.

Create a 128 Gb sdcard:

~/Library/Android/sdk/tools/mksdcard 128G sdcard.ini
Thomas Hagström
  • 4,371
  • 1
  • 21
  • 27