Hi everyone,
I'm trying to build an app which contains a page where the user can select an image from the gallery on their phone.
The approach I've taken is to create a DependencyService for image selection (following the dependency service guide)
Interface in the shared code:
public interface IGalleryImageService
{
Uri SelectImage();
}
Android implementation (trying to follow the select a gallery image recipe):
[assembly: Dependency(typeof(GalleryImageService_Android))]
namespace DropZone.Droid
{
public class GalleryImageService_Android : Java.Lang.Object, IGalleryImageService
{
public Uri SelectImage()
{
Context androidContext = Forms.Context;
Intent imageIntent = new Intent();
imageIntent.SetType("image/*");
imageIntent.SetAction(Intent.ActionGetContent);
androidContext.StartActivity(Intent.CreateChooser(imageIntent, "Select photo"));
// How do I retrieve the image the user selects?
}
}
}
This successfully opens the gallery application on my Android phone but I do not know how to retrieve the image that the user selected. The select a gallery image recipe said to call StartActivityForResult which is not available Forms.Context (the closest I found was StartActivity).
How can I retrieve the result of the user selection in the gallery? Am I taking the right approach? I'm completely new to Xamarin so any input/guidance would really be appreciated!