Esempio n. 1
0
        internal static AccessState GetLocationManagerStatus(this AndroidContext context, bool gpsRequired, bool networkRequired)
        {
            var lm = context.GetSystemService <LocationManager>(Context.LocationService);

            if (context.IsMinApiLevel(28) && !lm.IsLocationEnabled)
            {
                return(AccessState.Disabled);
            }

            if (networkRequired && !lm.IsProviderEnabled(LocationManager.NetworkProvider))
            {
                return(AccessState.Disabled);
            }

            if (gpsRequired && !lm.IsProviderEnabled(LocationManager.GpsProvider))
            {
                return(AccessState.Disabled);
            }

            return(AccessState.Available);
        }
Esempio n. 2
0
        internal static AccessState GetCurrentLocationAccess(this AndroidContext context, bool background, bool fineAccess)
        {
            var status = context.GetLocationManagerStatus(false);

            if (status != AccessState.Available)
            {
                return(status);
            }

            if (context.IsMinApiLevel(29) && background)
            {
                status = context.GetCurrentAccessState(ACCESS_BACKGROUND_LOCATION);
                if (status != AccessState.Available)
                {
                    return(status);
                }
            }
            var next = fineAccess ? P.AccessFineLocation : P.AccessCoarseLocation;

            status = context.GetCurrentAccessState(next);

            return(status);
        }
Esempio n. 3
0
        internal static async Task <AccessState> RequestLocationAccess(this AndroidContext context, bool background, bool fineAccess)
        {
            var status = context.GetLocationManagerStatus(false);

            if (status != AccessState.Available)
            {
                return(status);
            }

            var locationPerm = fineAccess ? P.AccessFineLocation : P.AccessCoarseLocation;

            if (context.IsMinApiLevel(29) && background)
            {
                return(await context
                       .RequestAccess
                       (
                           ACCESS_BACKGROUND_LOCATION,
                           locationPerm
                       )
                       .ToTask());
            }

            return(await context.RequestAccess(locationPerm).ToTask());
        }