TimothyP
TimothyP

Reputation: 21755

After taking 2 pictures in a MonoDroid app the camera app stops working

In a MonoDroid app, the following code is used to start the native camera application:

    internal void TakePicture(int pictureId)
    {
        var uri = ContentResolver.Insert(MediaStore.Images.Media.ExternalContentUri, new ContentValues());

        var intent = new Intent(MediaStore.ActionImageCapture);
        intent.PutExtra(MediaStore.ExtraOutput, uri);
        StartActivityForResult(intent, ACTIVITY_RESULT_PICTURE_TAKEN);

        pictureId = pictureId;
        pictureUri = uri;
    }

After the picture has been taken, it's handled here:

    protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
    {
        if (requestCode == ACTIVITY_RESULT_PICTURE_TAKEN)
        {
            if (resultCode == Result.Ok)
            {
                /* The URI is not a valid path, but something internal to Android
                 * See
                 * https://stackoverflow.com/questions/8448796/monodroid-setting-imageview-to-image-stored-on-sdcard
                 * for more information. */

                if (OnPictureTaken != null)
                    OnPictureTaken(this, new PictureTakenEventArgs(pictureId, GetRealPathFromURI(pictureUri)));
            }
        }
    }

The first 2 attempts to take a picture always succeed, but the 3rd time the Android camera application allows you to take pictures but it doesn't close and it doesn't return the picture to the application anymore... (The event handler above doesn't get called either).

We're testing this on Asus Transformer 101 tablets (multiple firmware versions)

PS: I found this entry, but I think it's a different problem.

error after taking several pictures using the android camera

Any suggestions?

Update: When taking low resolution pictures, the problem does not occur

Upvotes: 0

Views: 591

Answers (1)

Travis
Travis

Reputation: 261

I had a similar problem on my Transformer as well, but my problem was that it never worked. I don't think I ever tried requesting a different image size though. This post helped me, it was Donn Felker's answer that did the trick for me. I had to ensure an empty file was created before starting the camera intent in order for the camera application to allow the OK button to finish the intent.

Upvotes: 1

Related Questions