Reputation: 233
I'd like to take a photo from Xamarin Android (not Forms) and have it take the shot, and return the photo, skipping the Retry and OK links at the bottom of the screen.
I'm not using any special library, just passing an intent as shown here:
https://www.c-sharpcorner.com/article/camera-application-create/
Here's my code to call the camera and the returned code:
private void BtnCamera_Click(object sender, System.EventArgs e)
{
Intent intent = new Intent(MediaStore.ActionImageCapture);
StartActivityForResult(intent, 0);
}
protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
Bitmap bitmap = (Bitmap)data.Extras.Get("data");
AddPicturesToList(bitmap); // This adds the photo to a scrollable list
}
I have seen elsewhere you can do this but Xamarin is giving me an error the REQUEST_IMAGE_CAPTURE does not exist in the current context.
private void BtnCamera_Click(object sender, System.EventArgs e)
{
Intent intent = new Intent(MediaStore.ActionImageCapture);
intent.PutExtra("android.intent.extra.quickCapture", true);
StartActivityForResult(intent, REQUEST_IMAGE_CAPTURE); // <<<< Not working
}
Is there anything wrong with doing it this way?
Upvotes: 0
Views: 495
Reputation: 14981
StartActivityForResult(intent, REQUEST_IMAGE_CAPTURE);
the second parameter is an int type RequestCode
,it's an int greater than or equal to 0
,you could determine which Activity is turned off based on the returned requestCode in the OnActivityResult
.
So in the case,have you defined the REQUEST_IMAGE_CAPTURE
in your activity ?
Upvotes: 1