Xamarin.Android Camera2 API Camera don`t appears in default apps

Максим Кутлев 1 Reputation point
2021-03-28T07:10:11.477+00:00

I downloaded the sample Сamera2 API code to my device. In another app, I want to launch a third-party camera, but I can't select the one I downloaded.

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,293 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. JessieZhang-MSFT 7,706 Reputation points Microsoft Vendor
    2021-03-29T08:23:17.613+00:00

    Hello,

    Welcome to our Microsoft Q&A platform!

    You can try the following code, it works on my side:

           string packageName = "Camera2Basic.Camera2Basic";  
    
           button.Click += delegate {  
                try  
                {  
    
                    PackageManager pm = Android.App.Application.Context.PackageManager;  
    
                    if (IsAppInstalled(packageName))  
                    {  
    
                        Intent intent = pm.GetLaunchIntentForPackage(packageName);  
                        if (intent != null)  
                        {  
    
                            intent.SetFlags(ActivityFlags.NewTask);  
                            Android.App.Application.Context.StartActivity(intent);  
                        }  
                    }  
    
                    else  
                    {  
    
                        Intent intent = pm.GetLaunchIntentForPackage("Camera2Basic.Camera2Basic");  
                        if (intent != null)  
                        {  
    
                            intent.SetFlags(ActivityFlags.NewTask);  
                            Android.App.Application.Context.StartActivity(intent);  
                        }  
                    }  
                }  
                catch (ActivityNotFoundException)  
                {  
                   
                }  
    
            };  
    

    Best Regards,

    Jessie Zhang

    ---
    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.