question

87217497 avatar image
0 Votes"
87217497 asked JessieZhang-2116 commented

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

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.

dotnet-xamarinforms
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

JessieZhang-2116 avatar image
0 Votes"
JessieZhang-2116 answered JessieZhang-2116 commented

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.



· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello, thanx for the answer, but i resolved my problem with another solution. I added above my CameraActivity page right near that Manifest String [Activity (Label = "Camera2Basic", MainLauncher = true, Icon = "@drawable/icon")]

my Intent Filter which contains this code

[IntentFilter(new[] { "android.media.action.IMAGE_CAPTURE" }, Categories = new[] { Intent.CategoryDefault})]

0 Votes 0 ·

Congrats, and thanks for your support for xamarin.

0 Votes 0 ·