question

6666666 avatar image
0 Votes"
6666666 asked JarvanZhang-MSFT commented

MediaStore.Images.Media.InsertImage is deprecated which I should use instead?

MediaStore.Images.Media.InsertImage is deprecated

dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

JarvanZhang-MSFT avatar image
0 Votes"
JarvanZhang-MSFT answered JarvanZhang-MSFT commented

Hello,​

Welcome to our Microsoft Q&A platform!

The Media.InsertImage method was deprecated in API level 29. Try using ContentValues class to achieve the function instead.

if (Build.VERSION.SdkInt >= BuildVersionCodes.Q)
{
    var contentValues = new ContentValues();
    contentValues.Put(MediaStore.MediaColumns.DisplayName, file_name);
    contentValues.Put(MediaStore.Files.FileColumns.MimeType, "image/png");
    contentValues.Put(MediaStore.MediaColumns.RelativePath, Android.OS.Environment.DirectoryPictures + "relativePath");
    contentValues.Put(MediaStore.MediaColumns.IsPending, 1);
}

Similar issue: https://stackoverflow.com/a/57737524/11083277

Best Regards,

Jarvan Zhang


If the response is helpful, please click "Accept Answer" and upvote it.

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.


· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you Jarvan.

but the Media.InsertImage can insert bitmap to the Pictures but ContentValues can not.

0 Votes 0 ·

Media.InsertImage has two different ways: passing bitmap and path to insert the image. ContentValues doen't provide the code to handle the bitmap, please get the path from the image and pass the path to the ContentValues to perform the work.

0 Votes 0 ·

Hi, @6666666
I have not heard from you for a couple of days. Please let me know if there is anything that I can help here.

0 Votes 0 ·
Show more comments