External SD Card Access

Part of the requirements for my app is that it stores it’s data in the external SD card, not in the phone’s internal SD card. This is because we can control the size of the external SD card, where we have no control over the size of the internal SD card. If you haven’t figured it out, our application will generate a lot of images and other data that will be stored on the external SD card and uploaded to our server when the device is returned to our office.

I have set the write access option in the player settings to “External (SDCard)”, thinking that would allow me to write to the “/storage/extSdCard” path. While I can validate that the path exists, I am still getting an access denied error when attempting to write to that path.

I’ve been googling and binging all morning for this, and still have gotten no where with it. Can someone please shed some light on this ASAP? My deadline is fast approaching in just 3 weeks, and I need to get this requirement set in and working.

Pls post your tested phones and your code related to the problem :slight_smile:

This determines what the external file path is, it works, and on my Galaxy Mega it is returning the first option (which i know is there)

private static string GetExternalFilePath()
{
if (Directory.Exists(“/storage/extSdCard”)) return “/storage/extSdCard”;
if (Directory.Exists(“/storage/sdcard1”)) return “/storage/sdcard1”;
if (Directory.Exists(“/storage/usbcard1”)) return “storage/usbcard1”;
if (Directory.Exists(“/storage/sdcard0”)) return “/storage/sdcard0”;
return Application.persistentDataPath;
}

I then build the path for my applcation’s data:

private static string _externalFilePath = “”;
public static string SiteVueDirectory
{
get
{
if (string.IsNullOrEmpty(_externalFilePath))
{
_externalFilePath = GetExternalFilePath();
}
return string.Format(“{0}/SiteVue”, _externalFilePath);
}
}

Finally I build the test file’s full path:

public static string SiteListFile { get { return string.Format(“{0}/sites.dat”, SiteVueDirectory); } }

With all that done, i do the following:

if (!Directory.Exists(Globals.SiteVueDirectory)) Directory.CreateDirectory(Globals.SiteVueDirectory);

string testString = “This is a test string”;
var txtFile = File.AppendText(Globals.SiteListFile);
txtFile.Write(testString);
txtFile.Close();

However, i’m getting access denied errors when attempting to create the directory. I have even tried just saving the text file into the path that is stored into _externalFilePath, same thing, access denied errors.

I don’t normally bump stuff, but I’m quickly running out of time on this project and any help is appreciated. This IS the only requirement of the app that I’m struggling with.

I just tested in on an galaxy grand prime. Writing an simple txt file, hardcoded, so no other bugs are likely. It failed too, so im sorry. But works on other phones like lg g2/3. Couldnt find an workaround :confused:

Hello,
did someone found a solution?
I also can not write to sd-card nor read from sd-card…
nor is Unity installing the App on SD-Card… all options are checkt…
duhhh these Unity 5.x specials drive me nuts…
With Unity 4 all is fine…

No. The end result that I had to accept is that we can’t really control where the app data gets saved.