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

mc 4,476 Reputation points
2021-07-01T09:59:39.893+00:00

MediaStore.Images.Media.InsertImage is deprecated

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,348 questions
0 comments No comments
{count} votes

Accepted answer
  1. JarvanZhang 23,961 Reputation points
    2021-07-02T07:06:20.847+00:00

    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.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.