Can't detect back button when showing camera screen

tanvhtanvh Member ✭✭
edited April 19 in Xamarin.Forms
public partial class TakePhotoPage
{
    private bool _firstLoading =true;~~~~~~~~~~~~
    protected override void OnAppearing()
            {
                if (_firstLoading)
                {
                    TakePicture();
                    _firstLoading = false;
                }
                if (backEvent == 1)
                {
                    base.OnAppearing();
                    DependencyService.Get<IOrientationService>().SetOrientation(DeviceOrientation.Portrait);
                }
            }

            protected override void OnDisappearing()
            {
                base.OnDisappearing();
                DependencyService.Get<IOrientationService>().SetOrientation(DeviceOrientation.Portrait);
            }

            async void TakePicture()
            {
                viewModel.IsBusy = true;
                await CrossMedia.Current.Initialize();
                viewModel.IsBusy = false;
                if (!CrossMedia.Current.IsTakePhotoSupported)
                {
                    return;
                }
                string prefix = DateTime.Today.ToString("dd-MM-yyyy");
                var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
                {
                    SaveToAlbum = true,
                    SaveMetaData = true,
                    Directory = prefix,
                    MaxWidthHeight = 1650,
                    CompressionQuality = 75
                }); // show camera here

                if (file == null)
                {
                    return;
                }
    }
}

i try override some method to detect back button. but it's only working when click back button at TakePhotoPage, in camera screen , it's not working.
Have anything detect when click back button at camera screen ?????? I want detect to redirect to another page when click back button in camera screen(not back button of navigation bar)- Need Android & IOS Pls

Thanks All.

Best Answer

  • LandLuLandLu Xamurai
    Accepted Answer

    When the user clicks the back button to return to your TakePhotoPage, the file is null. You could detect this behavior through this variable's value:

    if (file == null)
    {
        // This means come to this page with back or cancel button
        // Navigate to the page as you want    
    }
    

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai
    Accepted Answer

    When the user clicks the back button to return to your TakePhotoPage, the file is null. You could detect this behavior through this variable's value:

    if (file == null)
    {
        // This means come to this page with back or cancel button
        // Navigate to the page as you want    
    }
    
  • tanvhtanvh Member ✭✭

    Thanks you so much. it's work well.

Sign In or Register to comment.