Hello,
Welcome to our Microsoft Q&A platform!
I created a basic demo to test the function with the following code, it works as expected. The only difference is MimeType, please set the type for the file separately. For example, set MimeType to application/pdf if you want to save a pdf file. You could use switch
to detect the file type.
if (Android.OS.Build.VERSION.SdkInt > BuildVersionCodes.Q)
{
ContentResolver resolver = context.ContentResolver;
ContentValues contentValues = new ContentValues();
contentValues.Put(MediaStore.MediaColumns.DisplayName, fileName);
contentValues.Put(MediaStore.MediaColumns.MimeType, "image/png");
contentValues.Put(MediaStore.MediaColumns.RelativePath, "Download/" + "test");
Android.Net.Uri imageUri = resolver.Insert(MediaStore.Downloads.ExternalContentUri, contentValues);
var os = resolver.OpenOutputStream(imageUri);
BitmapFactory.Options options = new BitmapFactory.Options();
options.InJustDecodeBounds = true;
var bitmap = BitmapFactory.DecodeStream(stream);
bitmap.Compress(Bitmap.CompressFormat.Png, 100, os);
os.Flush();
os.Close();
}
Best Regards,
Jarvan Zhang
If the response is helpful, 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.