Exemple #1
0
        private async Task <bool> CheckLocationPermisionsAsync()
        {
            Plugin.Permissions.Abstractions.PermissionStatus permissionLocation = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Location);

            Plugin.Permissions.Abstractions.PermissionStatus permissionLocationAlways = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.LocationAlways);

            Plugin.Permissions.Abstractions.PermissionStatus permissionLocationWhenInUse = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.LocationWhenInUse);

            bool isLocationEnabled = permissionLocation == Plugin.Permissions.Abstractions.PermissionStatus.Granted ||
                                     permissionLocationAlways == Plugin.Permissions.Abstractions.PermissionStatus.Granted ||
                                     permissionLocationWhenInUse == Plugin.Permissions.Abstractions.PermissionStatus.Granted;

            if (isLocationEnabled)
            {
                return(true);
            }

            await CrossPermissions.Current.RequestPermissionsAsync(Permission.Location);

            permissionLocation = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Location);

            permissionLocationAlways = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.LocationAlways);

            permissionLocationWhenInUse = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.LocationWhenInUse);

            return(permissionLocation == Plugin.Permissions.Abstractions.PermissionStatus.Granted ||
                   permissionLocationAlways == Plugin.Permissions.Abstractions.PermissionStatus.Granted ||
                   permissionLocationWhenInUse == Plugin.Permissions.Abstractions.PermissionStatus.Granted);
        }
Exemple #2
0
        private async Task GetPermissionsDroid()
        {
            Plugin.Permissions.Abstractions.PermissionStatus status = PermissionStatus.Unknown;
            bool beforeNotLet = false;

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

                if (status != PermissionStatus.Granted)
                {
                    if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(Permission.Location))
                    {
                        beforeNotLet = true;
                    }

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

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

                if (status == PermissionStatus.Granted)
                {
                    if (beforeNotLet)
                    {
                        ToolbarItems.Remove(requestLocationItem);
                        (mainGrid.Children[0] as StackLayout).Children.Remove(lblLocError);
                        IsBusy = true;
                        LoadingFragment();
                    }

                    Xamarin.Essentials.Location results = await InternalGetLocation();

                    App.Latitude  = results.Latitude;
                    App.Longitude = results.Longitude;
                    ShowInfo();
                }
                else if (status == PermissionStatus.Denied)
                {
                    ReqLocationToolbarItem();
                }
                else if (status == PermissionStatus.Unknown)
                {
                    ReqLocationToolbarItem();
                }
                else
                {
                    await DisplayAlert("Error", "Error not expected", "OK");
                }
            }
            catch (Exception ex)
            {
                await DisplayAlert("Error: " + ex, "55", "55");
            }
        }
Exemple #3
0
        public static async void RequestLocationPermission()
        {
            PermissionStatus status = await CrossPermissions.Current.CheckPermissionStatusAsync <LocationPermission>();

            if (status != PermissionStatus.Granted)
            {
                await CrossPermissions.Current.RequestPermissionAsync <LocationPermission>();
            }
        }
        public static async Task <Plugin.Permissions.Abstractions.PermissionStatus> CheckLocationServices()
        {
            try
            {
                Plugin.Permissions.Abstractions.PermissionStatus status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Location);

                Plugin.Permissions.Abstractions.PermissionStatus status2 = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.LocationWhenInUse);

                Plugin.Permissions.Abstractions.PermissionStatus status3 = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.LocationAlways);

                Console.WriteLine("Location Permissions: Location: " + status.ToString() + ", When In Use: " + status2.ToString() + ", Always: " + status3.ToString());
                if (status3 != Plugin.Permissions.Abstractions.PermissionStatus.Granted)
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        if (Device.RuntimePlatform == Device.iOS)
                        {
                            ILocationManager manager = DependencyService.Get <ILocationManager>();
                            manager.RequestBackgroundLocation();
                        }
                    });
                }
                else
                {
                    try
                    {
                        var request  = new GeolocationRequest(GeolocationAccuracy.Lowest, new TimeSpan(0, 0, 0, 0, 100));
                        var location = await Geolocation.GetLocationAsync(request);

                        if (location != null)
                        {
                            Console.WriteLine($"Latitude: {location.Latitude}, Longitude: {location.Longitude}, Altitude: {location.Altitude}");
                        }
                    }
                    catch (FeatureNotSupportedException)
                    {
                        return(Plugin.Permissions.Abstractions.PermissionStatus.Denied);
                    }
                    catch (FeatureNotEnabledException)
                    {
                        return(Plugin.Permissions.Abstractions.PermissionStatus.Denied);
                    }
                }
                return(status3);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
                return(Plugin.Permissions.Abstractions.PermissionStatus.Denied);
            }
        }
Exemple #5
0
        private async void btnScan_Clicked(object sender, EventArgs e)
        {
            btnScan.IsEnabled = false;
            PermissionStatus status = await CrossPermissions.Current.CheckPermissionStatusAsync <CameraPermission>();

            if (status != PermissionStatus.Granted)
            {
                status = await CrossPermissions.Current.RequestPermissionAsync <CameraPermission>();
            }
            if (status != PermissionStatus.Granted)
            {
                await DisplayAlert("Odmowa", "Skanowanie kodu QR wymaga uprawnień do użycia kamery. Użytkownik odmówił tego uprawnienia. Spróbuj jeszcze raz i przyznaj odpowiednie uprawnienie", "OK");
            }
            else
            {
                var options = new ZXing.Mobile.MobileBarcodeScanningOptions
                {
                    PossibleFormats = new List <ZXing.BarcodeFormat>
                    {
                        ZXing.BarcodeFormat.QR_CODE
                    },
                    TryHarder   = false,
                    AutoRotate  = false,
                    TryInverted = false,
                };
                scanPage = new ZXingScannerPage();
                scanPage.AutoFocus();
                scanPage.OnScanResult += (result) =>
                {
                    //DateTime _start = DateTime.Now;
                    scanPage.IsScanning = false;

                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        Navigation.PopAsync();
                        PopupNavigation.Instance.PushAsync(new LoadingScreen(), true);
                        try
                        {
                            //check if this is MES process string
                            string[] mesStr = Regex.Split(result.Text, ";");
                            if (mesStr.Length == 7)
                            {
                                //there are 7 fields split by ; in the string, there's good chance it comes from MES
                                MesString ms = new MesString();
                                try
                                {
                                    ms.MesId          = mesStr[0];
                                    ms.MesDate        = DateTime.Parse(mesStr[1]);
                                    ms.SetName        = mesStr[2];
                                    ms.ActionTypeName = mesStr[3];
                                    ms.Reason         = mesStr[5];
                                }
                                catch (Exception ex)
                                {
                                    await DisplayAlert("Problem z kodem", string.Format("Coś poszło nie tak podczas deserializacji kodu {0}", result.Text) + ". Opis błędu: " + ex.Message, "OK");
                                }
                                try
                                {
                                    //check if such a mesId exists before creating new one
                                    ProcessKeeper pKeeper = new ProcessKeeper();
                                    Process nProcess      = await pKeeper.GetProcess(ms.MesId);

                                    //pass everything to ProcessPage.xaml
                                    if (nProcess == null)
                                    {
                                        await Application.Current.MainPage.Navigation.PushAsync(new ProcessPage(ms));
                                    }
                                    else
                                    {
                                        await Application.Current.MainPage.Navigation.PushAsync(new ProcessPage(ms, nProcess, true));
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Static.Functions.CreateError(ex, "No connection", nameof(scanPage.OnScanResult), this.GetType().Name);
                                }
                            }
                            else if (result.Text.Contains("<Part>"))
                            {
                                //it's a part
                                string res = result.Text.Replace("<Part>", "");

                                Part Part = await new PartKeeper().GetByToken(res);
                                if (Part != null)
                                {
                                    if (Part.IsArchived == true)
                                    {
                                        await Application.Current.MainPage.DisplayAlert("Część zarchiwizowana", "Ta część została zarchiwizowana! Być może ta część występuje teraz pod nowym numerem, w takim przypadku należy wydrukować i okleić ją nowym kodem", "OK");
                                    }
                                    else
                                    {
                                        await Application.Current.MainPage.Navigation.PushAsync(new PartPage(Part));
                                    }
                                }
                                else
                                {
                                    DependencyService.Get <IToaster>().ShortAlert($"Nie znaleziono części oznaczonej kodem {res}..");
                                }
                            }
                            else
                            {
                                //try to find place of such token
                                Place = await Keeper.GetPlace(result.Text);
                                if (Place == null)
                                {
                                    await DisplayAlert("Brak dopasowań", string.Format("Zeskanowany kod: {0} nie odpowiada żadnemu istniejącemu zasobowi. Spróbuj zeskanować kod jeszcze raz.", result.Text), "OK");
                                }
                                else
                                {
                                    try
                                    {
                                        if (Place.IsArchived == true)
                                        {
                                            await Application.Current.MainPage.DisplayAlert("Zasób zarchiwizowany", "Ten zasób został zarchiwizowany! Być może ten zasób występuje teraz pod nowym numerem, w takim przypadku należy wydrukować i okleić go nowym kodem", "OK");
                                        }
                                        else
                                        {
                                            await Navigation.PushAsync(new ScanningResults(Place, true));
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        if (PopupNavigation.Instance.PopupStack.Any())
                                        {
                                            await PopupNavigation.Instance.PopAllAsync(true);
                                        }                                                                                                 // Hide loading screen
                                        await DisplayAlert("Brak połączenia", "Nie można połączyć się z serwerem. Prawdopodobnie utraciłeś połączenie internetowe. Upewnij się, że masz połączenie z internetem i spróbuj jeszcze raz", "OK");
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            await DisplayAlert("Brak połączenia", "Nie można połączyć się z serwerem. Prawdopodobnie utraciłeś połączenie internetowe. Upewnij się, że masz połączenie z internetem i spróbuj jeszcze raz", "OK");
                        }
                        if (PopupNavigation.Instance.PopupStack.Any())
                        {
                            await PopupNavigation.Instance.PopAllAsync(true);
                        }                                                                                                     // Hide loading screen
                    });
                };

                await Navigation.PushAsync(scanPage);
            }

            btnScan.IsEnabled = true;
        }