Problems with OnActivityResult

1

I'm making an application for the mobile phone and what I'm trying to do is that when I take a picture by pressing a button the camera opens and when I give it to accept the image I'm saved, but I'm never saved.

I was debugging and what it does is get into TakePicture and the camera turns on but then never gets in OnActivityResult and I do not know how to fix it.

private void TakeAPicture (object sender, EventArgs eventArgs)
    {
        Intent intent = new Intent(MediaStore.ActionImageCapture);
        try
        {
            if (PermissionManager.CheckCameraPermission(Activity))
            {


                StartActivityForResult(intent, 0);


            }
            else
            {
                PermissionManager.RequestCameraPermission(Activity);
            }
        }
        catch (Exception e)
        {
            Toast.MakeText(Activity, GetString(Resource.String.toast_error_camera), ToastLength.Long).Show();
            Crashes.TrackError(e);
        }


    }



    public override void OnActivityResult (int requestCode, int resultCode, Intent data)
    {
        base.OnActivityResult(requestCode, resultCode, data);

        if (resultCode != 0)
        {
            try
            {



                Bitmap bitmap = bitmap = (Bitmap)data.Extras.Get("data");

                Matrix matrix = new Matrix();
                matrix.PostRotate(90);
                Bitmap bmp = Bitmap.CreateBitmap(bitmap, 0, 0, bitmap.Width, bitmap.Height, matrix, true);

                if (bmp == null)
                    return;

                Bitmap bmpResized = ImageUtils.ResizeBitmap2(bmp, 600);

                if (bmpResized == null)
                    return;

                selectedImage = bmpResized;

                vImage.SetImageBitmap(selectedImage);

            }
            catch (Exception e)
            {
                Toast.MakeText(Activity, GetString(Resource.String.toast_error_camera), ToastLength.Long).Show();
                Crashes.TrackError(e);
            }

            // Dispose of the Java side bitmap.
            GC.Collect();

        }


    }
    
asked by user102455 07.12.2018 в 10:27
source

1 answer

0

Review the documentation related to StartActivityForResult :

 StartActivityForResult(intent, 0);

you are actually defining to run the code block when resultCode is different from 0:

   if (resultCode != 0)
        {
         ...
         ...
         ...
         }

I suggest you change the logic using Result.OK :

  

Result.OK: Result of the standard activity: successful operation.

   if (resultCode == Result.OK)
        {
         ...
         ...
         ...
         }else{
           Toast.MakeText(Activity, "Ocurrió un error a tomar la foto", ToastLength.Long).Show();
         }
    
answered by 10.12.2018 в 17:14