コード例 #1
0
		private File GetVideoFile(Context context)
		{
			return new File (context.GetExternalFilesDir (null), "video.mp4");
		}
コード例 #2
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)));
			}
		}