Ok, I am at a bit lost on how to use the "OnActivityResult" on Xamarin.Forms.
I have a Class that implements a custom Xamarin.forms Interface that does the work of interacting with the camera and photo gallery to get images from the device.
my class looks something like this:
public class Media : IMedia
{
Activity context;
/// <summary>
/// Initializes a new instance of the class.
/// </summary>
public Media()
{
context = Forms.Context as Activity;
//Check for Camera intent
takePictureIntent = new Intent (MediaStore.ActionImageCapture);
//context.StartActivityForResult (takePictureIntent, 0);
//Check for gallery intent
pickPictureIntent = new Intent();
pickPictureIntent.SetType ("image/*");
pickPictureIntent.SetAction (Intent.ActionGetContent);
//context.StartActivityForResult (Intent.CreateChooser(Intent, "Select Picture"), 1);
if (context.PackageManager.HasSystemFeature (PackageManager.FeatureCamera)) {
IsCameraAvailable = true;
IsPhotosSupported = true;
IsVideosSupported = true;
}
}
protected override void OnActivityResult (int requestCode, Result resultCode, Intent data)
{
switch (requestCode) {
case 0:
if (resultCode == Result.Ok) {
var selectedImage = data.Data;
//imageview.setImageUri(selectedImage);
}
break;
case 1:
if (resultCode == Result.Ok) {
var selectedImage = data.Data;
//imageview.setImageUri(selectedImage);
}
break;
}
}
}
I can easily make the Media class into a child of Activity, but it would be null as I don't know of a way to pass the current Forms.Context to the child. my other issue is that I need to override the OnActivityResult function, but I either don't have access or is null. How can I interact with the OnActivityResult while using the current context of the Xamarin.Forms application.