本文整理汇总了C#中Android.Content.Context.GetExternalFilesDir方法的典型用法代码示例。如果您正苦于以下问题:C# Context.GetExternalFilesDir方法的具体用法?C# Context.GetExternalFilesDir怎么用?C# Context.GetExternalFilesDir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Android.Content.Context
的用法示例。
在下文中一共展示了Context.GetExternalFilesDir方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetVideoFile
private File GetVideoFile(Context context)
{
return new File (context.GetExternalFilesDir (null), "video.mp4");
}
示例2: GetOutputMediaFile
/// <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)));
}
}