locked
Xam.Plugin.Media Saving photo in both internal storage and SD card on Android RRS feed

  • Question

  • User395545 posted

    I use Xam.Plugin.Media Camera option. My app takes photo and uploads this photo to remote server. I want the user to choose whether can save the picture or not save on phone while they use Xam.Plugin.Media Camera option. So I did a basic ui for this. After the user's choice, I set SaveToAlbum (true or false) It works on iOS good. But on android it doesn't work on SD card.

    After taking photo using " await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions { } ) ", the following cases are belowing:

    • If "SaveToAlbum = true" and phone camera setting is SD card, Xam.Plugin.Media is save photo twice, one to internal storage and one to SD card. (it should save one photo just internal storage)
    • If "SaveToAlbum = true" and phone camera setting is internal storage, Xam.Plugin.Media is save photo twice, just internal storage. (it should save one photo just internal storage)
    • If "SaveToAlbum = false" and phone camera setting is SD card, Xam.Plugin.Media is save photo once, just SD card. (it should never save)
    • If "SaveToAlbum = false" and phone camera setting is internal storage, Xam.Plugin.Media is save photo once, just internal. (it should never save)

    How can i fix this? Thank you.

    Friday, July 3, 2020 5:30 AM

All replies

  • User382871 posted

    After the user's choice, I set SaveToAlbum (true or false) It works on iOS good. But on android it doesn't work on SD card. When taking a photo it will still store temporary data, but also if needed make a copy to the public gallery (based on platform). This may be why the code works on ios but not on Android in your case.

    We could not change the library/platform settings, for this issue, you could save the photo according your need(delete the photo you don't want); ``` var file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions { SaveToAlbum = ... });

    //Get the public album path var aPpath = file.AlbumPath;

    //Get private path var path = file.Path;

    if (Device.RuntimePlatform == Device.Android) { //delete the photo of the corresponding path manaually
    } ```

    Friday, July 3, 2020 9:05 AM
  • User395545 posted

    @Jarvan I've tried this, but photo name is changing when saving SD card and internal storage. So photo names are different in sd card, internal storage and uploaded. I cannot get photo names from photo album and so I cannot delete the photo

    Friday, July 3, 2020 11:16 AM
  • User382871 posted

    If the plugin doesn't work fine at the Android platform for you, try to achieve the take and pick media function using native code instead. You could use DependencyService to call the function code in pcl.

    Check the links: https://github.com/xamarin/docs-archive/tree/master/Recipes/android/otherux/cameraintent/takeapictureandsaveusingcamera_app https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/dependency-service/photo-picker

    Monday, July 6, 2020 9:15 AM
  • User395545 posted

    @Jarvan The problem is not happen on every android phone. For example, Samsungphone is working properly but LG phone is not. When opening camera on Samsung phone at the first time, asks "default storage space will be sd card" (ok or cancel). When opening camera on LG phone at the first time, asks "do photos save to sd card" (ok or no) but, it is saving photos whatever the answer

    Monday, July 6, 2020 10:34 AM