Esempio n. 1
0
        internal static AndroidUri GetShareableFileUri(FileBase file)
        {
            Java.IO.File sharedFile;
            if (FileProvider.IsFileInPublicLocation(file.FullPath))
            {
                // we are sharing a file in a "shared/public" location
                sharedFile = new Java.IO.File(file.FullPath);
            }
            else
            {
                var root = FileProvider.GetTemporaryRootDirectory();

                var tmpFile = FileSystem.GetEssentialsTemporaryFile(root, file.FileName);

                System.IO.File.Copy(file.FullPath, tmpFile.CanonicalPath);

                sharedFile = tmpFile;
            }

            // create the uri, if N use file provider
            if (HasApiLevelN)
            {
                return(FileProvider.GetUriForFile(sharedFile));
            }

            // use the shared file path created
            return(AndroidUri.FromFile(sharedFile));
        }
Esempio n. 2
0
 public FileBase(FileBase file)
 {
     FullPath    = file.FullPath;
     ContentType = file.ContentType;
     FileName    = file.FileName;
     PlatformInit(file);
 }
Esempio n. 3
0
        internal static AndroidUri GetShareableFileUri(FileBase file)
        {
            Java.IO.File sharedFile;
            if (FileProvider.IsFileInPublicLocation(file.FullPath))
            {
                // we are sharing a file in a "shared/public" location
                sharedFile = new Java.IO.File(file.FullPath);
            }
            else
            {
                var rootDir = FileProvider.GetTemporaryDirectory();

                // create a unique directory just in case there are multiple file with the same name
                var tmpDir = new Java.IO.File(rootDir, Guid.NewGuid().ToString("N"));
                tmpDir.Mkdirs();
                tmpDir.DeleteOnExit();

                // create the new temprary file
                var tmpFile = new Java.IO.File(tmpDir, file.FileName);
                tmpFile.DeleteOnExit();

                var fileUri = AndroidUri.Parse(file.FullPath);
                if (fileUri.Scheme == "content")
                {
                    using var stream     = Application.Context.ContentResolver.OpenInputStream(fileUri);
                    using var destStream = System.IO.File.Create(tmpFile.CanonicalPath);
                    stream.CopyTo(destStream);
                }
                else
                {
                    System.IO.File.Copy(file.FullPath, tmpFile.CanonicalPath);
                }

                sharedFile = tmpFile;
            }

            // create the uri, if N use file provider
            if (HasApiLevelN)
            {
                var providerAuthority = AppContext.PackageName + ".fileProvider";
                return(FileProvider.GetUriForFile(
                           AppContext.ApplicationContext,
                           providerAuthority,
                           sharedFile));
            }

            // use the shared file path created
            return(AndroidUri.FromFile(sharedFile));
        }
Esempio n. 4
0
 internal void PlatformInit(FileBase file)
 {
 }
Esempio n. 5
0
 internal void PlatformInit(FileBase file) =>
 throw new NotImplementedInReferenceAssemblyException();
Esempio n. 6
0
 public EmailAttachment(FileBase file)
     : base(file)
 {
 }
 internal void PlatformInit(FileBase file) =>
 throw ExceptionUtils.NotSupportedOrImplementedException;
Esempio n. 8
0
 public EmailAttachment(FileBase file)
     : base(file)
 {
     ExperimentalFeatures.VerifyEnabled(ExperimentalFeatures.EmailAttachments);
 }
Esempio n. 9
0
 internal void PlatformInit(FileBase file)
 {
     File = file.File;
 }
Esempio n. 10
0
 public OpenFileRequest(string title, FileBase file)
 {
     Title = title;
     File  = new ReadOnlyFile(file);
 }
 public OpenFileRequest(string title, FileBase file)
 {
     ExperimentalFeatures.VerifyEnabled(ExperimentalFeatures.OpenFileRequest);
     Title = title;
     File = new ReadOnlyFile(file);
 }
Esempio n. 12
0
 internal void PlatformInit(FileBase file)
 {
     ContentType = PlatformGetContentType(file.FullPath);
 }