I'm trying to build a camera app on Android using Xamarin. What I am trying to do is when user hits the "take image" button, camera will automatically switch the back camera to front camera and capture the image, which means the "take image" button will do 2 things: switch camera and capture image at the same time.
I am new to Xamarin and developing Android app. I've searched for many tutorials to build camera app, but they seem to be simple and I do not see any override function when user hit the "take image" button. Here my code in Main activity (just to build the simple camera app):
ImageView imageView;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
var btnCamera = FindViewById<Button>(Resource.Id.btnCamera);
imageView = FindViewById<ImageView>(Resource.Id.imageView);
btnCamera.Click += BtnCamera_Click;
}
protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
Bitmap bitmap = (Bitmap)data.Extras.Get("data");
imageView.SetImageBitmap(bitmap);
}
// When user tap on the button, open camra app
private void BtnCamera_Click(object sender, System.EventArgs e)
{
Intent intent = new Intent(MediaStore.ActionImageCapture);
StartActivityForResult(intent, 0);
}
Any idea would help, thanks a lot.