【问题标题】:Image downloaded to Phone storage but does not appear in Gallery in Xamarin.Android图像已下载到手机存储,但未出现在 Xamarin.Android 的图库中
【发布时间】:2016-08-26 06:06:52
【问题描述】:

我是 Xamarin 的新手。我正在 Xamarin.forms 中开发应用程序 但是已经在 Xamarin.Android 中编写了一个小的本机代码来下载 Android 设备中的图像。 现在的问题是我可以将图像下载到设备的手机存储中,但它没有出现在图库中,但它存在于手机存储中,我可以在文件管理器中看到它。 谁能建议我在这里做错了什么。 以下是我的代码:

    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);
    }

【问题讨论】:

标签: xamarin xamarin.android


【解决方案1】:

我可以在下载后立即在图库中看到我下载的图像。 下面一行代码对我有用。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多