1

With Android 4.4.2 I have have to change Environment.getExternalStorageDirectory() to use context.getExternalFilesDir(null)

This works perfectly fine on 4.4.2 Emulator and my Galaxy S3 but on the Galaxy S3 it is using the internal memory and not the SDCard

I have used (How can I get external SD card path for Android 4.0+?) Answer with 18 to find the SDCard

Is there anywhere round this issue on the Galaxy S3 with combining getExternalFilesDir() and the Galaxy S3

Thanks

Community
  • 1
  • 1
James Dudley
  • 915
  • 4
  • 15
  • 35

1 Answers1

3

This works perfectly fine on 4.4.2 Emulator and my Galaxy S3 but on the Galaxy S3 it is using the internal memory and not the SDCard

It is using external storage on both the emulator and the Galaxy S3. I just completed a blog post series explaining what internal storage, external storage, and removable storage all really mean in Android.

Is there anywhere round this issue on the Galaxy S3 with combining getExternalFilesDir() and the Galaxy S3

You are welcome to use getExternalFilesDirs() (note the plural) on Android 4.4+. If the array has more than one entry, the second and subsequent entries will be on removable media (SD card, USB storage, etc.).

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thanks. How does this work for pre4.4. Do you have to add a switch in then for before and after 4.4? – James Dudley Apr 21 '14 at 22:06
  • Do you have a link to how use getExternalFilesDirs()? – James Dudley Apr 21 '14 at 22:07
  • 1
    @JamesDudley: "Do you have to add a switch in then for before and after 4.4?" -- that, or [use `ContextCompat`](https://developer.android.com/reference/android/support/v4/content/ContextCompat.html) and its version of `getExternalFilesDirs()`, which works on all versions of Android. "Do you have a link" -- https://developer.android.com/reference/android/content/Context.html#getExternalFilesDir%28java.lang.String%29 – CommonsWare Apr 21 '14 at 22:09
  • I mean to use the plural version. I added context.getExternalFilesDirs() but errors and wants to cast to context – James Dudley Apr 21 '14 at 22:12
  • @JamesDudley: Sorry, but I do not understand your last comment. Please click on the link to `getExternalFilesDirs()` to see sample code. Note that your build target (e.g., Project > Properties > Android in Eclipse) needs to be 19 or higher. – CommonsWare Apr 21 '14 at 22:18
  • Ok. Not set the Build to be targetSDK only the manifest. So for 4.4 you use that and before you use the old version? – James Dudley Apr 21 '14 at 22:37
  • @JamesDudley: Yes, or you use `ContextCompat` and its version of `getExternalFilesDirs()`, which gives consistent results across all versions of Android, as I mentioned a couple of comments ago. – CommonsWare Apr 21 '14 at 22:43
  • Thanks. Missed that. Added ContextCompat and using getExternalFilesDirs() on my Galaxy S3. Works fine but only brings back 1 Result. The internal Memory and not the SDCard. I set the values to be getExternalFilesDirs(context, null). Is that Correct? – James Dudley Apr 22 '14 at 08:14
  • @JamesDudley: "Works fine but only brings back 1 Result" -- correct, a location on external storage. That is all you will get for Android 4.3 and below. However, bear in mind that not all Android 4.4+ devices have removable storage either, so you need to handle the case where there is only one result for all Android devices. Please read the blog posts that I linked to in the question for more explanation of what is going on with all of these different storage areas. – CommonsWare Apr 22 '14 at 11:02