MohammadTofi
MohammadTofi

Reputation: 385

Create folder in internal memory?

I try to create a folder in the internal memory android, but after I build an app in unity then run an app on android, I get the exception:

"unauthorizedaccessexception access to the path is denied"

void Start()
    {
        //Create cashe  
        AddCacheAtPath("cashe");
    }
    private void AddCacheAtPath(string path)
    {
         if (!Directory.Exists(path))
              Directory.CreateDirectory(path);

           Cache newCache = Caching.AddCache(path);

            //Make sure your new Cache is valid
            if (newCache.valid)
            {
                //If you wanted to set your newly created cache to the active cache
                Caching.currentCacheForWriting = newCache;
            }   
    }

Upvotes: 2

Views: 944

Answers (1)

Hitesh Anshani
Hitesh Anshani

Reputation: 1549

You should enable this permission READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permissions in Android. You can follow this blog to enable the permission in runtime or you can give in manifest https://blog.xamarin.com/requesting-runtime-permissions-in-android-marshmallow/

Or Check

Check and if user has not yet granted granted READ_EXTERNAL_STORAGE & WRITE_EXTERNAL_STORAGE, use the bellow code;

var permissions = new string[] { Manifest.Permission.ReadExternalStorage, Manifest.Permission.WriteExternalStorage };
            RequestPermissions(permissions, 77);

See references references 2

Upvotes: 2

Related Questions