简体   繁体   中英

Writing Access denied to removable SD Card

I'm having a problem with writing to my external sd card. I'm getting a UnauthorizedAccessException whenever I try to write to it. I've already checked WriteExternalStorage in the Android Manifest.
Because GetExternalStoragePublicDirectory , ExternalStorageDirectory etc. are all returning the path to the internal storage, I'm using a manual path, /storage/6363-3065/ . If I'm writing to my internal storage, the program runs without error, but it throws an Exception when writing to the sd card.
Can I do anything to solve this? I mean, it can't be impossible, because other programs like my file manager can do it without root or anything...

Edit:

I'm using a LG G4 with Android 6.0. Code is simple:

string filepath = "/storage/6363-3065/Temp/tempfile.temp";
Directory.CreateDirectory(Path.GetDirectoryName(filepath));

Try this:

     string text="TestText";
     var dir = System.IO.Path.Combine(Android.OS.Environment.ExternalStorageDirectory.ToString(), "yourAppName");
     if (Directory.Exists(dir) == false)
                {
                    Directory.CreateDirectory(dir);
                }
       string dbFileSDCard = System.IO.Path.Combine(Android.OS.Environment.ExternalStorageDirectory.ToString(), "yourAppName/YourFile.txt");
       System.IO.File.WriteAllText(@dbFileSDCard, text);

do you get errors?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM