protected override void OnActivityResult(int requestCode, [Android.Runtime.GeneratedEnum] Result resultCode, Intent data)
        {
            string Tag = "CheckSettingActivity.OnActivityResult";

            base.OnActivityResult(requestCode, resultCode, data);
            if (data == null)
            {
                return;
            }
            LocationSettingsStates locationSettingsStates = LocationSettingsStates.FromIntent(data);

            log.Info(Tag, $"CheckLocationSettings completed: {locationSettingsStates.LSSToString()}");
            switch (requestCode)
            {
            // Check for the integer request code originally supplied to StartResolutionForResult().
            case 0:
                switch (resultCode)
                {
                case Result.Ok:
                    log.Info(Tag, "User agreed to make required location settings changes.");
                    // Nothing to do. StartLocationupdates() gets called in OnResume again.
                    break;

                case Result.Canceled:
                    log.Info(Tag, "User chose not to make required location settings changes.");
                    break;
                }
                break;
            }
        }
        private async void OnClickCheckSetting(object sender, EventArgs eventArgs)
        {
            string Tag = "CheckSetting";

            LocationRequest locationRequest = new LocationRequest();

            LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
            builder.AddLocationRequest(locationRequest)
            .SetAlwaysShow(false)
            .SetNeedBle(false);
            var locationSettingsResponseTask = settingsClient.CheckLocationSettingsAsync(builder.Build());

            try
            {
                await locationSettingsResponseTask;
                if (locationSettingsResponseTask.IsCompleted && locationSettingsResponseTask.Result != null)
                {
                    LocationSettingsResponse response = locationSettingsResponseTask.Result;
                    LocationSettingsStates   locationSettingsStates = response.LocationSettingsStates;
                    log.Info(Tag, $"CheckLocationSettings completed: {locationSettingsStates.LSSToString()}");
                }
            }
            catch (Exception e)
            {
                if (e is ApiException apiException)
                {
                    log.Error(Tag, $"CheckLocationSetting Failed. ErrorMessage: {apiException.Message} ErrorCode: {apiException.StatusCode}");

                    int statuesCode = apiException.StatusCode;
                    if (statuesCode == LocationSettingsStatusCodes.ResolutionRequired)
                    {
                        try
                        {
                            //When the StartResolutionForResult is invoked, a dialog box is displayed, asking you to open the corresponding permission.
                            ResolvableApiException resolvableApiException = (ResolvableApiException)e;
                            resolvableApiException.StartResolutionForResult(this, 0);
                        }
                        catch (IntentSender.SendIntentException sendIntentException)
                        {
                            log.Error(Tag, "PendingIntent unable to execute request.");
                        }
                    }
                }
                else
                {
                    log.Error(Tag, $"CheckLocationSetting Failed: {e.Message}");
                }
            }
        }
Exemple #3
0
        public static string LSSToString(this LocationSettingsStates states)
        {
            string result = string.Empty;

            result += $"BlePresent: {states.BlePresent}\n";
            result += $"BleUsable: {states.BleUsable}\n";
            result += $"GnssPresent: {states.GnssPresent}\n";
            result += $"GnssUsable: {states.GnssUsable}\n";
            result += $"LocationPresent: {states.LocationPresent}\n";
            result += $"LocationUsable: {states.LocationUsable}\n";
            result += $"NetworkLocationPresent: {states.NetworkLocationPresent}\n";
            result += $"NetworkLocationUsable: {states.NetworkLocationUsable}\n";
            result += $"HMSLocationPresent: {states.HMSLocationPresent}\n";
            result += $"IsHMSLocationUsable: {states.HMSLocationUsable}";

            return(result);
        }
        public override void OnActivityResult(int requestCode, int resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);
            LocationSettingsStates states = LocationSettingsStates.FromIntent(data);

            switch (requestCode)
            {
            case RequestCode:
                switch (resultCode)
                {
                case (int)Android.App.Result.Ok:
                    mLocationCallback.MyLocation += MLocationCallback_MyLocation;
                    break;

                case (int)Android.App.Result.Canceled:
                    break;

                default:
                    break;
                }
                break;
            }
        }