.NET MAUI Camera Not Opening on Android 15 (Works on Other Versions)

Sakshi Poojary 95 Reputation points
2025-03-21T16:11:00.44+00:00

In my .NET MAUI application, I have the option to open the camera using MediaPicker.CapturePhotoAsync(). The camera works fine on other Android versions, but on Android 15, it does not open.

Below is the code I am using to open the camera:

try
{
    photo = await MediaPicker.CapturePhotoAsync();
    if (photo != null)
    {
        var newFile = Path.Combine(FileSystem.CacheDirectory, photo.FileName);
        using (var stream = await photo.OpenReadAsync())
        using (var newStream = File.OpenWrite(newFile))
            await stream.CopyToAsync(newStream);

        profileImage.Source = newFile;
        isPicture = true;
    }
}
catch (Exception ex)
{
    Console.WriteLine($"CapturePhotoAsync THREW: {ex.Message}");
}

I also tried the below approach, but this also does not work on Android 15:

try
{
    if (MediaPicker.Default.IsCaptureSupported)
    {
        FileResult photo = await MediaPicker.Default.CapturePhotoAsync();

        if (photo != null)
        {
            picPath = photo.FullPath;

            // Open the photo as a stream
            using Stream sourceStream = await photo.OpenReadAsync();

            // Load the image using SkiaSharp
            using SKBitmap originalBitmap = SKBitmap.Decode(sourceStream);

            // Define the desired width and height
            int desiredWidth = 800; // change as needed
            int desiredHeight = 600; // change as needed

            // Resize the image
            using SKBitmap resizedBitmap = originalBitmap.Resize(new SKImageInfo(desiredWidth, desiredHeight), SKFilterQuality.High);

            // Encode the resized image to a byte array
            using SKImage image = SKImage.FromBitmap(resizedBitmap);
            using SKData encodedData = image.Encode(SKEncodedImageFormat.Jpeg, 75); // 75 is the quality, you can change it
            byte[] resizedImageBytes = encodedData.ToArray();

            // Save the resized image to local storage
            string localFilePath = Path.Combine(FileSystem.CacheDirectory, photo.FileName);
            File.WriteAllBytes(localFilePath, resizedImageBytes);

            // Set the image source
            profileImage.Source = localFilePath;
            isPicture = true;
            isCamera = true;

            // Update other variables
            imageByteContents = new ByteArrayContent(resizedImageBytes);
        }
        else
        {
            isPicture = true;
            isCamera = true;
        }
        isGallery = false;
    }
}
catch (Exception exception)
{
    Console.WriteLine($"CapturePhotoAsync THREW: {exception}");
}

My problem is the camera does not open on Android 15, while it works fine on other Android versions. Please suggest a solution.

Update

I have resolved this issue by adding the IMAGE_CAPTURE in manifest. Now I am able to open the camera in android 15.

<queries>
    <intent>
        <action android:name="android.media.action.IMAGE_CAPTURE" />
    </intent>
</queries>

But my current problem is after taking photo the photo is reversing.

The Image I clicked:

jgxhrfFd

Image on the UI after tick mark selection:

xaFQ3EiI

This issue is only on Android 15 version devices.

Developer technologies | .NET | .NET MAUI
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.