sharee.bike-App/LastenradBayern/ShareeBike.Android/Model/Device/SpecialFolder.cs

49 lines
1.3 KiB
C#
Raw Permalink Normal View History

2022-08-30 15:42:25 +02:00
using System;
using Serilog;
2024-04-09 12:53:23 +02:00
using ShareeBike.Model.Device;
2021-11-07 19:42:59 +01:00
using Xamarin.Forms;
2024-04-09 12:53:23 +02:00
[assembly: Dependency(typeof(ShareeBike.Droid.Model.Device.SpecialFolder))]
namespace ShareeBike.Droid.Model.Device
2021-11-07 19:42:59 +01:00
{
2022-09-06 16:08:19 +02:00
public class SpecialFolder : ISpecialFolder
{
/// <summary> Get the folder name of external folder to write to. </summary>
/// <returns> Name of the external folder. </returns>
public string GetExternalFilesDir()
{
string baseFolderPath = string.Empty;
try
{
var context = Android.App.Application.Context;
Java.IO.File[] dirs = context.GetExternalFilesDirs(null);
2021-11-07 19:42:59 +01:00
2022-09-06 16:08:19 +02:00
foreach (Java.IO.File folder in dirs)
{
bool IsRemovable = Android.OS.Environment.InvokeIsExternalStorageRemovable(folder);
bool IsEmulated = Android.OS.Environment.InvokeIsExternalStorageEmulated(folder);
2021-11-07 19:42:59 +01:00
2022-09-06 16:08:19 +02:00
if (IsRemovable
&& !IsEmulated)
{
baseFolderPath = folder.Path;
}
}
}
2021-11-07 19:42:59 +01:00
2022-09-06 16:08:19 +02:00
catch (Exception l_oException)
{
Log.Error("Getting external files directory failed. {@l_oException}", l_oException);
}
2021-11-07 19:42:59 +01:00
2022-09-06 16:08:19 +02:00
return baseFolderPath;
}
2021-11-07 19:42:59 +01:00
2022-09-06 16:08:19 +02:00
/// <summary> Gets the folder name of the personal data folder dir on internal storage. </summary>
/// <returns>Directory name.</returns>
public string GetInternalPersonalDir()
{
return Environment.GetFolderPath(Environment.SpecialFolder.Personal);
}
}
2021-11-07 19:42:59 +01:00
}