0

Before It gets brought up about my question already being asked, I would like to state that I have tried around 5 other options and possible solutions with no result.

Here is a snippet of my code. This is just a snippet. Upon testing the results of my code currently, a file is being saved in the main directory, /ScoutingApp. However, I would like to files to save in a folder /ScoutingApp/ on the MicroSD card so I can eject data more quickly.

        if (Environment.MEDIA_MOUNTED.equals(state)) {
        File root = Environment.getExternalStorageDirectory();
        File Dir = new File(root.getAbsolutePath() + "/ScoutingApp");
        if (!Dir.exists()) {
            Dir.mkdir();
        } else {

            filename = UUID.randomUUID().toString() + ".sql";
            File file = new File(Dir, filename);
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
Alex Webber
  • 93
  • 2
  • 10

1 Answers1

0

If the Android that your Fire OS is based on is Android 4.4+, you can try getExternalFilesDirs() on any Context (such as an Activity). Note the plural form — if this method returns 2+ items, the second and subsequent ones are on removable storage. Those locations will be specific for your app, and you can read from and write to those locations without permissions.

Note, though, that Fire OS is not completely compliant with the Play ecosystem's compatibility requirements, and so YMMV.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I tried using getExternalFilesDirs(), but am unsure what to pass into it as the parameter. – Alex Webber Mar 12 '16 at 14:52
  • @AlexWebber: Um, well, if you read [the docs](http://developer.android.com/reference/android/content/Context.html#getExternalFilesDirs%28java.lang.String%29) for that parameter, they have: "The type of files directory to return. May be null for the root of the files directory or one of the following constants for a subdirectory: DIRECTORY_MUSIC, DIRECTORY_PODCASTS, DIRECTORY_RINGTONES, DIRECTORY_ALARMS, DIRECTORY_NOTIFICATIONS, DIRECTORY_PICTURES, or DIRECTORY_MOVIES." Those constants are defined on `Environment`. So, pick whatever fits your needs best, such as `null`. – CommonsWare Mar 12 '16 at 14:55
  • Thank you for your continued help. It is saving a file in /0/, which another drive I guess. It needs to go into /sdcard1/, and I am unable to figure that out. – Alex Webber Mar 12 '16 at 15:15
  • @AlexWebber: ::shrug:: Iterate over the array you get back from `getExternalFilesDirs()` and log the results. Or, switch away from all of this and see if you can use [the Storage Access Framework](http://developer.android.com/guide/topics/providers/document-provider.html) to allow the user to choose where to put the file, as they may be able to choose removable storage that way. Removable storage is not Android's strong suit in general, and Fire OS is unlikely to improve upon that state. – CommonsWare Mar 12 '16 at 15:23
  • I was able to iterate over that array, and it returned two different ones. How would I save it to the second one, 0 is the internal, and 1 is the one I want. @CommonsWare – Alex Webber Mar 12 '16 at 21:30
  • @AlexWebber: Well, in Java, to access index 1 of an array, you use `[1]` notation. So, if you have `File[] extdirs=getExternalFilesDirs(null);` or something, and you validate that `extdirs` has 2+ elements via `extdirs.length`, you get the index 1 element via `extdirs[1]`. – CommonsWare Mar 12 '16 at 21:33