Example #1
0
        async Task <bool> RequestPermission()
        {
            if (await _permissions.CheckPermissionStatusAsync(Permission.Location) != PermissionStatus.Granted)
            {
                await _permissions.RequestPermissionsAsync(Permission.Location); //TODO Check result
            }

            return(await _permissions.CheckPermissionStatusAsync(Permission.Location) == PermissionStatus.Granted);
        }
Example #2
0
        public async void TryStartScanning(bool refresh = false)
        {
            try
            {
                var status = await permissions.CheckPermissionStatusAsync(Permission.Location);

                if (status != PermissionStatus.Granted)
                {
                    var permissionResult = await permissions.RequestPermissionsAsync(Permission.Location);

                    if (permissionResult.First().Value != PermissionStatus.Granted)
                    {
                        await userDialogs.AlertAsync("Permission denied. Not scanning.");

                        permissions.OpenAppSettings();
                        return;
                    }
                }
                if (IsStateOn && (refresh || !Devices.Any()) && !IsRefreshing)
                {
                    ScanForDevices();
                }
            }
            catch (Exception ex)
            {
            }
        }
Example #3
0
 // MUST be geant location permission
 private async void GetLocationPermission()
 {
     if (await _permissions.CheckPermissionStatusAsync(Permission.Location) != PermissionStatus.Granted)
     {
         await _permissions.RequestPermissionsAsync(Permission.Location);
     }
 }
        public override async Task OnAppearing()
        {
            //permissions
            PermissionStatus status = await permissions.CheckPermissionStatusAsync(Permission.Location);

            if (status != PermissionStatus.Granted)
            {
                var permissionsStatus = await permissions.RequestPermissionsAsync(Permission.Location);

                if (permissionsStatus.ContainsKey(Permission.Location) && permissionsStatus[Permission.Location] == PermissionStatus.Granted)
                {
                    await GetPositionAsync();
                }
                else
                {
                    //popup
                    return;
                }
            }
            else
            {
                geolocator.PositionChanged += Geolocator_PositionChanged;
                await geolocator.StartListeningAsync(new TimeSpan(0, 1, 0), 25);
            }
        }
        public async Task <Dictionary <Permission, PermissionStatus> > CheckMultipleAsync(string permissionRequestRationaleMessage, params Permission[] permissions)
        {
            var requestPermissions          = false;
            var shouldShowRequestPermission = false;
            var results = new Dictionary <Permission, PermissionStatus>();

            // Checks the permission status for every permission.
            for (var i = 0; i < permissions.Length; i++)
            {
                var permissionType = permissions[i];
                var status         = await permission.CheckPermissionStatusAsync(permissionType);

                results[permissionType] = status;

                if (status != PermissionStatus.Granted)
                {
                    requestPermissions           = true;
                    shouldShowRequestPermission |= await permission.ShouldShowRequestPermissionRationaleAsync(permissionType);
                }
            }

            if (shouldShowRequestPermission)
            {
                await dialogService.AlertAsync(permissionRequestRationaleMessage ?? "Authorize app permission to continue.");
            }

            if (requestPermissions)
            {
                results = await permission.RequestPermissionsAsync(permissions);
            }

            return(results);
        }
Example #6
0
        public async Task <bool> ValidateGeolocationPermission()
        {
            try
            {
                var current = await _permission.CheckPermissionStatusAsync(Permission.Location);

                if (current != PermissionStatus.Granted)
                {
                    await _permission.ShouldShowRequestPermissionRationaleAsync(Permission.Location);

                    var all = await _permission.RequestPermissionsAsync(new[]
                                                                        { Permission.Location });

                    current = all[Permission.Location];
                }

                if (current == PermissionStatus.Granted)
                {
                    return(true);
                }

                _dialogService.DisplayAlert("No permission granted",
                                            "Location is required for GPS tracking.", "Ok").RunSynchronously();
                return(false);
            }
            catch (Exception e)
            {
                _dialogService.DisplayAlert("Something wrong with permission granting", e.Message, "Ok").RunSynchronously();
                throw;
            }
        }
        private async void ImportData(FileData filedata)
        {
            var status = await _crossPermissions.CheckPermissionStatusAsync(Permission.Storage);

            if (status != PermissionStatus.Granted)
            {
                if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(Permission.Storage))
                {
                    await Application.Current.MainPage.DisplayAlert("Need storage", "Request storage permission", "OK");
                }

                var results = await CrossPermissions.Current.RequestPermissionsAsync(Permission.Storage);

                //Best practice to always check that the key exists
                if (results.ContainsKey(Permission.Storage))
                {
                    status = results[Permission.Storage];
                }
            }
            if (status != PermissionStatus.Granted)
            {
                return;
            }

            var dataBaseConnection = (IDataBaseConnection)ServiceManager.ServiceProvider.GetService(typeof(IDataBaseConnection));

            dataBaseConnection.ImportTrainingsData(filedata);
        }
        // MUST be geant location permission
        private async void GetLocationPermission()
        {
            if (await _permissions.CheckPermissionStatusAsync(Permission.Location) != PermissionStatus.Granted)
            {
                if (Device.RuntimePlatform == Device.Android)
                {
                    await _userDialogs.AlertAsync("This app collects location data in the background.  In terms of the features using this location data in the background, this App collects location data when it is reading temperature RFID tag in the “Magnus S3 with GPS for Advantech” page.  The purpose of this is to correlate the RFID tag with the actual GNSS location of the tag.  In other words, this is to track the physical location of the logistics item tagged with the RFID tag.");
                }
//                await _userDialogs.AlertAsync("This app collects location data to enable temperature RFID tag inventory with GNSS location mapped to each tag data when the app is open and in the foreground.  This location data collection is not carried out when the app is closed or not in use.   Specifically, this App collects location data when it is reading temperature RFID tag in the “Magnus S3 with GPS for Advantech” page.");

                await _permissions.RequestPermissionsAsync(Permission.Location);
            }
        }
        public async Task <bool> RequestCameraPermissionIfNeeded()
        {
            var status = await permissions.CheckPermissionStatusAsync(Permission.Camera);

            if (status != PermissionStatus.Granted)
            {
                var results = await permissions.RequestPermissionsAsync(new[] { Permission.Camera });

                status = results[Permission.Camera];
            }

            return(status == PermissionStatus.Granted);
        }
Example #10
0
        private async Task RequestPermissionsIfNotGranted()
        {
            PermissionStatus = await _permissionService.CheckPermissionStatusAsync(Permission.Microphone);

            if (PermissionStatus != PermissionStatus.Granted)
            {
                if (await _permissionService.ShouldShowRequestPermissionRationaleAsync(Permission.Microphone))
                {
                    DisplayAlert("Permissions", "You should authorize us to use your microphone.", "OK");
                }

                var results = await _permissionService.RequestPermissionsAsync(Permission.Microphone);

                if (results.ContainsKey(Permission.Microphone))
                {
                    PermissionStatus = results[Permission.Microphone];
                }
            }
        }
        private async Task <bool> HasLocationPermissionAsync()
        {
            if (global::Xamarin.Forms.Device.RuntimePlatform == global::Xamarin.Forms.Device.Android)
            {
                var status = await _permissions.CheckPermissionStatusAsync <LocationPermission>().ConfigureAwait(false);

                if (status != PermissionStatus.Granted)
                {
                    var permissionResult = await _permissions.RequestPermissionAsync <LocationPermission>().ConfigureAwait(false);

                    if (permissionResult != PermissionStatus.Granted)
                    {
                        _permissions.OpenAppSettings();
                        return(false);
                    }
                }
            }

            return(true);
        }
Example #12
0
        async void Grant_Clicked(object sender, EventArgs e)
        {
            var status = await permissionsPlugin.CheckPermissionStatusAsync(Permission.Location);

            // On iOS direct user to Settings if the user has denied access.
            if (status == PermissionStatus.Denied && Device.RuntimePlatform == Device.iOS)
            {
                var openSettingsAnswer = await DisplayAlert("Locatiebepaling vereist", "Zet alstublieft locatiebepaling aan.", "Open instellingen", "Annuleer");

                if (openSettingsAnswer)
                {
                    permissionsPlugin.OpenAppSettings();
                }
            }
            //
            else if (status == PermissionStatus.Granted)
            {
                Settings.Current.PermissionsGranted = true;
                await Navigation.PopModalAsync();
            }
            else
            {
                // iOS implementation of plugin returns a dictionary with the updated permissions (after the user chooses
                // grants or denies permission.
                // Android implementation does not return a dictionary with the latest permissions. Only
                // returns a dictionary with old permissions (or current if the requested permission is already granted)
                GrantButton.Text = "Next";
                var resultDict = await permissionsPlugin.RequestPermissionsAsync(Permission.Location);

                // Android: code after this point is not called.

                PermissionStatus resultStatus = resultDict[Permission.Location];

                if (resultStatus == PermissionStatus.Granted)
                {
                    Settings.Current.PermissionsGranted = true;
                    await Navigation.PopModalAsync();
                }
            }
        }
Example #13
0
        private async Task RefreshHandle()
        {
            if (Xamarin.Forms.Device.RuntimePlatform == Xamarin.Forms.Device.Android)
            {
                var status = await _permissions.CheckPermissionStatusAsync(Permission.Location);

                if (status != PermissionStatus.Granted)
                {
                    var permissionResult = await _permissions.RequestPermissionsAsync(Permission.Location);

                    if (permissionResult.First().Value != PermissionStatus.Granted)
                    {
                        await _userDialogs.AlertAsync("Permission denied. Not scanning.");

                        _permissions.OpenAppSettings();
                        return;
                    }
                }
            }
            await ScanForDevices();

            IsRefreshing = false;
        }
        private async void TryStartScanning(bool refresh = false)
        {
            if (Xamarin.Forms.Device.OS == Xamarin.Forms.TargetPlatform.Android)
            {
                var status = await _permissions.CheckPermissionStatusAsync(Permission.Location);

                if (status != PermissionStatus.Granted)
                {
                    var permissionResult = await _permissions.RequestPermissionsAsync(Permission.Location);

                    if (permissionResult.First().Value != PermissionStatus.Granted)
                    {
                        _userDialogs.ShowError("Permission denied. Not scanning.");
                        return;
                    }
                }
            }

            if (IsStateOn && (refresh || !Devices.Any()) && !IsRefreshing)
            {
                ScanForDevices();
            }
        }
Example #15
0
 public Task <PermissionStatus> CheckPermissionsAsync <T>() where T : BasePermission, new()
 {
     return(_permissions.CheckPermissionStatusAsync <T>());
 }
Example #16
0
 public Task <PermissionStatus> CheckPermissionStatusAsync(Permission permission)
 {
     return(facade.CheckPermissionStatusAsync(permission));
 }
Example #17
0
        private async Task <PermissionStatus> CheckPermissionAsync(PermissionName permissionNameToCheck)
        {
            var crossPermissionsStatus = await permissions.CheckPermissionStatusAsync(permissionNameToCheck);

            return(crossPermissionsStatus);
        }
 public async Task <PermissionStatus> CheckPermissionStatusAsync(FeaturePermission featurePermission)
 {
     return((PermissionStatus)await _permissions.CheckPermissionStatusAsync(ToPermission(featurePermission)));
 }