Share via

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

mc 6,801 Reputation points
2021-07-01T09:59:39.893+00:00

MediaStore.Images.Media.InsertImage is deprecated

Developer technologies | .NET | Xamarin
0 comments No comments
{count} votes

Answer accepted by question author
  1. JarvanZhang 23,971 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' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.