コード例 #1
0
        public void DeleteFile(string path)
        {
            Android.Net.Uri uri;

            string auth     = "com.Linaq.LinaqStorage.Android.fileprovider";
            string mimeType = Android.Webkit.MimeTypeMap.Singleton.GetMimeTypeFromExtension(Android.Webkit.MimeTypeMap.GetFileExtensionFromUrl(path.ToLower()));

            if (mimeType == null)
            {
                mimeType = "*/*";
            }

            if (path.StartsWith("content://"))
            {
                uri = Android.Net.Uri.Parse(path);

                DocumentFile pickedDir = DocumentFile.FromSingleUri(Android.App.Application.Context, uri);
                if (pickedDir.Exists())
                {
                    pickedDir.Delete();
                }
            }
            else
            {
                var file = new Java.IO.File(Path.Combine(Android.App.Application.Context.FilesDir.Path, path));
                file.Delete();
                //  uri = FileProvider.GetUriForFile(Android.App.Application.Context, auth, file);
            }
        }
コード例 #2
0
 internal SafFile(Android.Net.Uri uri) : base(uri.Path ?? string.Empty)
 {
     _fileUri           = uri ?? throw new ArgumentNullException(nameof(uri));
     _directoryDocument = DocumentFile.FromSingleUri(Application.Context, uri);
     if (string.IsNullOrEmpty(Path))
     {
         Path = _directoryDocument.Name;
     }
 }
コード例 #3
0
        public static String getFileRealNameFromUri(Context context, Android.Net.Uri fileUri)
        {
            if (context == null || fileUri == null)
            {
                return(null);
            }
            DocumentFile documentFile = DocumentFile.FromSingleUri(context, fileUri);

            if (documentFile == null)
            {
                return(null);
            }
            return(documentFile.Name);
        }
コード例 #4
0
        /// <inheritdoc/>
        public async Task <byte[]> ReadPickedFile()
        {
            if (_pickedUri == null)
            {
                throw new Exception("Pick a file first before it can be read.");
            }

            DocumentFile file = DocumentFile.FromSingleUri(_context, _pickedUri);

            using (Stream stream = _context.ContentResolver.OpenInputStream(file.Uri))
            {
                byte[] result = new byte[stream.Length];
                await stream.ReadAsync(result, 0, (int)stream.Length);

                return(result);
            }
        }