Hello,
You need to use DependencyService to implement the function in different platforms. You can refer to DependencyService to get more details.
You can refer to the following content:
In Android:
You can try the following code to save photos into public directory:
private void CreateFileTest(string internalPath, string name)
{
// decode a bitmap from a local file path.
Bitmap bitmap = BitmapFactory.DecodeFile(internalPath);
System.IO.Stream fos;
if (Build.VERSION.SdkInt >= BuildVersionCodes.Q)
{
ContentValues contentValues = new ContentValues();
contentValues.Put(MediaStore.IMediaColumns.DisplayName, name + ".jpg");
contentValues.Put(MediaStore.IMediaColumns.MimeType, "image/jpg");
contentValues.Put(MediaStore.IMediaColumns.RelativePath, Android.OS.Environment.DirectoryPictures);
var imageUri = Android.App.Application.Context.ContentResolver.Insert(MediaStore.Images.Media.ExternalContentUri, contentValues);
fos = Android.App.Application.Context.ContentResolver.OpenOutputStream(imageUri);
bitmap.Compress(Bitmap.CompressFormat.Jpeg, 100, fos);
}
else
{
String imagesDir = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryPictures).ToString();
var path = System.IO.Path.Combine(imagesDir, name , ".jpg");
fos = new FileStream(path,FileMode.Create);
bitmap.Compress(Bitmap.CompressFormat.Jpeg, 100, fos);
}
}
You can refer to Storage updates in Android 11 to know changes.
In IOS:
You can refer to Sharing with the Files app to know how to share files with the Files App.
In UWP:
You can use the following code to copy files:
private void CopyFileTest()
{
var sourcepath = "your photo path";
var targetpath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments));
// the 'true' means that will overwrite duplicate file.
System.IO.File.Copy(sourcepath, targetpath, true);
}
Then, the file will be copied to C:\Users\username\Documents\test.txt
.
You can refer to Environment.SpecialFolder Enum to get more details.
Best Regards,
Alec Liu.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.