1

I am newbie in Xamarin. I am developing an application in Xamarin.forms but have written a small native code in Xamarin.Android to download an image in Android Device. Now the problem is I am able to download image to Phone storage of device but it does not appear in Gallery but it is present in phone storage I can see it in file manager. Can anyone please suggest what am I doing wrong here. Below is my code:

    public void DownloadFile(byte[] data, string fileName, string fileType, string attachmentUrl)
    {
        string localPath = string.Empty;
        if (fileType == CAN.Model.Enums.FileTypes.Image.ToString())
        {
           localPath = Path.Combine(Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryPictures).AbsolutePath, fileName);                
        }
        File.WriteAllBytes(localPath, data);
    }
NewbieCoder
  • 377
  • 3
  • 16
  • Possible duplicate of [How can I refresh MediaStore on Android?](http://stackoverflow.com/questions/3300137/how-can-i-refresh-mediastore-on-android) – SushiHangover Aug 26 '16 at 06:27

1 Answers1

1

I am able to see my downloaded images in Gallery right after download. Below one line code did the trick for me.

    MediaScannerConnection.ScanFile(Android.App.Application.Context, new string[] { System.IO.Path.Combine(localPath, fileName) }, new string[] { "image / jpeg" }, null);
NewbieCoder
  • 377
  • 3
  • 16