jamesmontemagno / Xamarin.Plugins

Cross-platform Native API Access from Shared Code!
MIT License
1.3k stars 380 forks source link

PermissionStatus.Unknown #345

Closed mariusmuntean closed 8 years ago

mariusmuntean commented 8 years ago

Which Plugin does this impact: Xamarin.Plugins.Permissions

Bug

Version Number of Plugin: 1.1.7 Device Tested On: Nexus 7 (Android 6) and Oppo R5 (CM 13) Simulator Tested On:

Expected Behavior

When callingawait CrossPermissions.Current.RequestPermissionsAsync(new[] { Permission.Storage });a system dialog is shown when the user can grant/deny the requested permission

Actual Behavior

No dialog is shown and the status of the requested Permission is PermissionStatus.Unknown

Steps to reproduce the Behavior

Sample code:

 private async Task<bool> CheckExternalStoragePermission()
        {
            var externalStorageStatus = false;
            try
            {
                var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Storage);
                if (status != PermissionStatus.Granted)
                {
                    if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(Permission.Storage))
                    {
                        await Mvx.Resolve<IUserDialogs>().AlertAsync(Catalog.GetString("We need permission to store the downloaded files"),
                            Catalog.GetString("Permission to access storage"));
                    }

                    var results = await CrossPermissions.Current.RequestPermissionsAsync(new[] { Permission.Storage });
                    status = results[Permission.Storage];
                }

                if (status == PermissionStatus.Granted)
                {
                    externalStorageStatus = true;
                }
                else if (status != PermissionStatus.Unknown)
                {

                    await Mvx.Resolve<IUserDialogs>().AlertAsync(Catalog.GetString("Cannot continue sharing."), Catalog.GetString("Storage Permission Denied"));
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception while requesting Storage permission: "+ex);
                externalStorageStatus = false;
            }

            return externalStorageStatus;
        }
mariusmuntean commented 8 years ago

I acidentally deleted the MainApplication.cs file that the CurrentActivity plugin includes