Anirudha Gupta
Anirudha Gupta

Reputation: 9289

Camera not open in UWP in my xamarin.forms app?

From last few hours, I am trying to make a button, on button click the camera will open. I test it only UWP and it's not working as expected.

I tried with x64 and x86 both in UWP( to make sure it's not a platform related issue).

    private async void Button_Clicked(object sender, EventArgs e)
    {
        await CrossMedia.Current.Initialize();

        if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
        {
            DisplayAlert("No Camera", ":( No camera available.", "OK");
            return;
        }

        var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
        {
            Directory = "Sample",
            Name = "test.jpg"
        });

    }

the project is .net standard in 2017, Visual Studio has created the project in xamarin 3.0 and I test it in 2.4 too, nothing is shown yet.

in first few time my breakpoint was hitting in my xamarin.forms project but suddenly they stopped, Maybe it's async thing. Currently, when I debug and put breakpoint it navigates to app.xaml.cs and put my breakpoint there.

For testing it in a shared project, I created a testing project and put my code there, in that code my code in UWP was firing but nothing is opened (C# code didn't make any exception at runtime).

This project that I take my code from is .net standard in 2017, Please check and help, I am trying to solve it from last few hours.

Upvotes: 0

Views: 629

Answers (1)

Nico Zhu
Nico Zhu

Reputation: 32775

when I put breakpoint at debugging it's always goes to mainpage of UWP, what is wrong on my side

It's known issue in Visual Studio. Currently, there is a workaround that you could refer.

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugType>Full</DebugType>
</PropertyGroup>

Place the above code in the .NET Standard Library csproj file.

And I have tested your code with LifeCam HS-3000, it open the system camera as excepted. Please check if your camera is available. You could use system Camera application to verify this.

Upvotes: 1

Related Questions