tesses-vfs/Tesses.VirtualFilesystem.Saf/README.md

3.0 KiB

Tesses.VirtualFilesystem.Saf

A library to use Tesses.VirtualFilesystem with Storage Access Framework (Android)

Nuget

License

GPL3-only Licensed under GPL3

How to use (not presistant)

   ...
   using Tesses.VirtualFilesystem;
   using Tesses.VirtualFilesystem.Filesystems;
   using Android.Content;
   using AndroidX.DocumentFile.Provider;
   using Tesses.VirtualFilesystem.Extensions;
   ...

   void SomeActivityFunction()
   {
        SAFFileSystem.RequestDirectory(this,true);
   }    
   protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent? data)
   {
        if(requestCode == SAFFileSystem.RequestCode && resultCode == Result.Ok)
        {
            var res=SAFFileSystem.GetSAFFromResponse(this,data);
            if(res != null)
                HandleFilesystem(res);
        }
   }
   void HandleFilesystem(SAFFileSystem fs)
   {
        fs.CreateDirectory(Special.Root/"My Special Folder");
        //read https://gitea.site.tesses.net/tesses50/tesses-vfs to get up to speed
        //root is relative to the folder the user chose
        //so get subdir filesystem is not needed
   }

How to use (presistant)

   ...
   using Tesses.VirtualFilesystem;
   using Tesses.VirtualFilesystem.Filesystems;
   using Android.Content;
   using AndroidX.DocumentFile.Provider;
   using Tesses.VirtualFilesystem.Extensions;
   ...
   const string MySAFKey = "MySafKey";
   void SomethingWithContext()
   {
       var res= SAFFileSystem.GetSAFFromSharedStorage(this,MySAFKey);
       if(res != null)
            HandleFilesystem(res);
   }
   void SomeActivityFunction()
   {
        var res= SAFFileSystem.GetSAFFromSharedStorage(this,MySAFKey);
       if(res != null)
            HandleFilesystem(res);
       else
            SAFFileSystem.RequestDirectory(this,true,true);
   }    
   protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent? data)
   {
        if(requestCode == SAFFileSystem.RequestCode && resultCode == Result.Ok)
        {
            var res=SAFFileSystem.GetSAFFromResponsePresistant(this,data,MySAFKey);
            if(res != null)
                HandleFilesystem(res);
        }
   }
   void HandleFilesystem(SAFFileSystem fs)
   {
        fs.CreateDirectory(Special.Root/"My Special Folder");
        //read https://gitea.site.tesses.net/tesses50/tesses-vfs to get up to speed
        //root is relative to the folder the user chose
        //so get subdir filesystem is not needed
   }

How to revoke permissions

   ...
   using Tesses.VirtualFilesystem;
   using Tesses.VirtualFilesystem.Filesystems;
   using Android.Content;
   using AndroidX.DocumentFile.Provider;
   using Tesses.VirtualFilesystem.Extensions;
   ...
   const string MySAFKey = "MySafKey";
    void SomethingWithContext()
    {
        SAFFileSystem.Revoke(this,MySAFKey);
    }