コード例 #1
0
ファイル: PlatformExtensions.cs プロジェクト: IustinT/shiny
        public static AccessState GetCurrentLocationAccess(this IAndroidContext context, bool background, bool fineAccess, bool gpsRequired, bool networkRequired)
        {
            var status = context.GetLocationManagerStatus(gpsRequired, networkRequired);

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

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

            status = context.GetCurrentAccessState(next);

            return(status);
        }
コード例 #2
0
ファイル: PlatformExtensions.cs プロジェクト: IustinT/shiny
        public static async Task <AccessState> RequestLocationAccess(this IAndroidContext context, bool background, bool fineAccess, bool gpsRequired, bool networkRequired)
        {
            var status = context.GetLocationManagerStatus(gpsRequired, networkRequired);

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

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

            if (!context.IsMinApiLevel(29) || !background)
            {
                return(await context.RequestAccess(locationPerm).ToTask());
            }

            var access = await context
                         .RequestPermissions
                         (
                P.AccessBackgroundLocation,
                P.ForegroundService,
                locationPerm
                         )
                         .ToTask();

            if (!access.IsGranted(locationPerm))
            {
                return(AccessState.Denied);
            }

            if (!access.IsGranted(P.AccessBackgroundLocation))
            {
                return(AccessState.Restricted);
            }

            return(AccessState.Available);
        }