コード例 #1
0
        /// <summary>
        /// Gets the output media file.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="subdir">The subdir.</param>
        /// <param name="name">The name.</param>
        /// <param name="isPhoto">if set to <c>true</c> [is photo].</param>
        /// <returns>Uri.</returns>
        /// <exception cref="System.IO.IOException">Couldn't create directory, have you added the WRITE_EXTERNAL_STORAGE permission?</exception>
        private static Uri GetOutputMediaFile(Context context, string subdir, string name, bool isPhoto)
        {
            subdir = subdir ?? String.Empty;

            if (String.IsNullOrWhiteSpace(name))
            {
                name = MediaFileHelpers.GetMediaFileWithPath(isPhoto, subdir, string.Empty, name);
            }

            var mediaType = (isPhoto) ? Environment.DirectoryPictures : Environment.DirectoryMovies;

            using (var mediaStorageDir = new Java.IO.File(context.GetExternalFilesDir(mediaType), subdir))
            {
                if (!mediaStorageDir.Exists())
                {
                    if (!mediaStorageDir.Mkdirs())
                    {
                        throw new IOException("Couldn't create directory, have you added the WRITE_EXTERNAL_STORAGE permission?");
                    }

                    // Ensure this media doesn't show up in gallery apps
                    using (var nomedia = new Java.IO.File(mediaStorageDir, ".nomedia"))
                        nomedia.CreateNewFile();
                }

                return(Uri.FromFile(new Java.IO.File(MediaFileHelpers.GetUniqueMediaFileWithPath(isPhoto, mediaStorageDir.Path, name, File.Exists))));
            }
        }
コード例 #2
0
        /// <summary>
        /// Gets the output file name with folder.
        /// </summary>
        /// <param name="self">The self.</param>
        /// <param name="rootPath">The root folder.</param>
        /// <returns>System.String.</returns>
        public static string GetMediaFileWithPath(this MediaStorageOptions self, string rootPath)
        {
            var isPhoto   = !(self is VideoMediaStorageOptions);
            var name      = (self != null) ? self.Name : null;
            var directory = (self != null) ? self.Directory : null;

            return(MediaFileHelpers.GetMediaFileWithPath(isPhoto, rootPath, directory, name));
        }
コード例 #3
0
        /// <summary>
        /// Gets the unique filepath.
        /// </summary>
        /// <param name="self">The self.</param>
        /// <param name="rootPath">The root folder.</param>
        /// <param name="checkExists">The check exists.</param>
        /// <returns>System.String.</returns>
        public static string GetUniqueMediaFileWithPath(this MediaStorageOptions self, string rootPath,
                                                        Func <string, bool> checkExists)
        {
            var isPhoto = !(self is VideoMediaStorageOptions);
            var path    = self.GetMediaFileWithPath(rootPath);

            var folder = Path.GetDirectoryName(path);
            var name   = Path.GetFileNameWithoutExtension(path);

            return(MediaFileHelpers.GetUniqueMediaFileWithPath(isPhoto, folder, name, checkExists));
        }