Beispiel #1
0
        public static async Task <bool> GetPermissions(Permission permission)
        {
            bool stateEvent = false;

            try {
                var status = await CrossPermissions.Current.CheckPermissionStatusAsync(permission);

                if (status != PermissionStatus.Granted)
                {
                    if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(permission))
                    {
                        //await DisplayAlert("Need location", "Gunna need that location", "OK");
                    }

                    var results = await CrossPermissions.Current.RequestPermissionsAsync(permission);

                    //Best practice to always check that the key exists
                    if (results.ContainsKey(permission))
                    {
                        status = results[permission];
                    }
                }

                if (status == PermissionStatus.Granted)
                {
                    stateEvent = true;
                }
            }
            catch (Exception ex) {
                Console.WriteLine(ex.Message);
            }
            return(stateEvent);
        }
Beispiel #2
0
        public async Task checkPermission(Plugin.Permissions.Abstractions.Permission permission)
        {
            PermissionStatus permissionStatus = await CrossPermissions.Current.CheckPermissionStatusAsync(permission);

            if (permissionStatus != PermissionStatus.Granted)
            {
                var requestedPermissions = await CrossPermissions.Current.RequestPermissionsAsync(permission);
            }
        }
Beispiel #3
0
        public async Task <bool> RequestPermissionAsync()
        {
            var p = new Permission[1];

            p[0] = Permission.Storage;
            await CrossPermissions.Current.RequestPermissionsAsync(p);

            return(await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Storage) == PermissionStatus.Granted);
        }
        async Task <bool> CheckNecessaryPermissions(Plugin.Permissions.Abstractions.Permission permissionName)
        {
            var permStatus = await CrossPermissions.Current.CheckPermissionStatusAsync(permissionName);

            if (permStatus != PermissionStatus.Granted)
            {
                var results = await CrossPermissions.Current.RequestPermissionsAsync(new[] { permissionName });

                permStatus = results[permissionName];
            }
            return(await Task.FromResult(permStatus == PermissionStatus.Granted));
        }
        /// <summary>
        /// Устаревший метод, надо уходить от него
        /// </summary>
        /// <param name="permission"></param>
        /// <param name="warningText"></param>
        /// <returns></returns>
        public async System.Threading.Tasks.Task <bool> PermissionGrantedAsync(Plugin.Permissions.Abstractions.Permission permission, string warningText)
        {
            PermissionStatus status = PermissionStatus.Unknown;

            try
            {
                status = await CrossPermissions.Current.CheckPermissionStatusAsync(permission);

                if (status != PermissionStatus.Granted)
                {
                    var resultCheckRequest = await CrossPermissions.Current.RequestPermissionsAsync(permission);

                    foreach (var permissionItem in resultCheckRequest)
                    {
                        if (permissionItem.Value != PermissionStatus.Granted)
                        {
                            UserDialogs.Instance.Alert("Включить разрешение определения позиции можно через меню настроек системы", CommonResource.CommonMsg_Warning, CommonResource.CommonMsg_Ok);

                            /*MainThread.BeginInvokeOnMainThread(() =>
                             * {
                             * });*/
                            return(false);
                        }
                    }
                    bool resultRequest = await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(permission);

                    if (!resultRequest)
                    {
                        var results = await CrossPermissions.Current.RequestPermissionsAsync(permission);

                        if (results.ContainsKey(permission))
                        {
                            status = results[permission];
                        }
                    }
                }
            }
            catch (Exception)
            {
            }

            return(status == PermissionStatus.Granted);
        }
        /// <summary>
        /// Function to request a particular permission enumerated by the Permissions Plugin.
        /// </summary>
        /// <param name="permission">The permission to be requested.</param>
        /// <returns>A task containing either true if the permission is granted or false otherwise.</returns>
        public async Task <bool> RequestPermission(Plugin.Permissions.Abstractions.Permission permission)
        {
            try
            {
                var results = await CrossPermissions.Current.RequestPermissionsAsync(permission);

                var status = PermissionStatus.Unknown;
                //Best practice to always check that the key exists
                if (results.ContainsKey(permission))
                {
                    status = results[permission];
                }

                return(status == PermissionStatus.Granted);
            }
            catch
            {
                var text = "Error requesting permissions";
                Toast.MakeText(CrossCurrentActivity.Current.Activity, text, ToastLength.Short).Show();
                return(false);
            }
        }