How to get the path to the internal memory of the smartphone and the DCIM folder?

試著忘記壹切 提交于 2019-12-12 03:52:59

问题


How to get the path to the internal memory of the smartphone and the DCIM folder, then to save the photo there?

string directory = System.IO.Path.Combine(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath, Android.OS.Environment.DirectoryDownloads);
FileStream file = new FileStream(System.IO.Path.Combine(directory, "newProdict_" + product.Width + "x" + product.Height + ".png"), FileMode.OpenOrCreate);

回答1:


You can get the DCIM folder like that:

var dcimFolder = Android.OS.Environment.GetExternalStoragePublicDirectory(System.Environment.DirectoryDcim).Path;

For writing files you can use the nuget package PCLStorage so you already have everything in a cross platform manner:

var folder = await FileSystem.Current.GetFolderFromPathAsync(dcimFolder);
var file = await folder.CreateFileAsync("image.jpg", CreationCollisionOption.ReplaceExisting);
byte[] buffer = new byte[100];
using (System.IO.Stream stream = await file.OpenAsync(FileAccess.ReadAndWrite))
{
    stream.Write(buffer, 0, 100);
}


来源:https://stackoverflow.com/questions/44584067/how-to-get-the-path-to-the-internal-memory-of-the-smartphone-and-the-dcim-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!