示例#1
0
        private static List <FileInfo> GetAllStorages(Context context)
        {
            var storages = new List <FileInfo>();

            try
            {
                var externalStorageFiles = ContextCompat.GetExternalFilesDirs(context, null);
                var basePath             = $"/Android/data/{context.PackageName}/files";

                foreach (var file in externalStorageFiles)
                {
                    if (file != null)
                    {
                        var path = file.AbsolutePath;
                        if (path.Contains(basePath))
                        {
                            var finalPath = path.Replace(basePath, "");
                            if (IsValidPath(finalPath))
                            {
                                storages.Add(new FileInfo(new File(finalPath)));
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                //TODO log exception
                Toast.MakeText(context, "Failed to access storage", ToastLength.Short).Show();
            }

            return(storages);
        }
示例#2
0
        string GetExternalPath()
        {
            var dirs = ContextCompat.GetExternalFilesDirs(ApplicationContext, null);

            if (dirs.Count() == 1)
            {
                return(Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryMovies).Path);
            }
            else if (dirs.Last() != null)
            {
                return(dirs.Last().AbsolutePath);
            }
            else
            {
                return(Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryMovies).Path);
            }
        }
示例#3
0
        public static List <string> GetAllStorageLocations(Context context)
        {
            var appsDirs = ContextCompat.GetExternalFilesDirs(context, null);

            return(appsDirs.Select(file => file.ParentFile.ParentFile.ParentFile.ParentFile.AbsolutePath).ToList());
        }