question

RCBRChauhan-5224 avatar image
0 Votes"
RCBRChauhan-5224 asked RCBRChauhan-5224 commented

camera and location permission at runtime in xamarin forms

I have created a xamarin forms application and it requires two permission i.e i)Location and ii)Camera. I need to get both permissions at runtime but unfortunately i am able to get only one permission at a time when app starts.

Is there any solution to request both permission simultaneously at runtime.

Any advice or suggestion would be great help for me.

dotnet-xamarin
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

LeonLu-MSFT avatar image
0 Votes"
LeonLu-MSFT answered RCBRChauhan-5224 commented

Hello,​

Welcome to our Microsoft Q&A platform!

If you want to achieve the permission request like following screenshot(with 2 popup dialog) when app starts..

140736-image.png 140697-image.png


Just add the following code to the OnCreate method of MainActivity.cs

protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);

            if(ContextCompat.CheckSelfPermission(this, Manifest.Permission.Camera) != (int)Permission.Granted|| ContextCompat.CheckSelfPermission(this, Manifest.Permission.AccessFineLocation) != (int)Permission.Granted)
            {
                RequestPermissions(new string[] { Manifest.Permission.Camera, Manifest.Permission.AccessFineLocation }, 0);
            }

            

            LoadApplication(new App());
        }


If you want to request Camara and location in the one popup system permission, it cannot be achieved. This popup permission dialog it comes from the native android, Android OS will expain the permission's usage for every dangerous permission.


Best Regards,

Leon Lu



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.



image.png (15.6 KiB)
image.png (14.5 KiB)
· 1
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.

Thanks, It works as i wanted.

0 Votes 0 ·