yayaa / LocationManager

Simplify getting user's location for Android
806 stars 187 forks source link

Setting screen request code #125

Open Ahmed-Ganna opened 1 year ago

Ahmed-Ganna commented 1 year ago

When i press enable GPS button in the default provider GPS dialog, it opens the setting screen with request code RequestCode.GPS_ENABLE but onActivityResult is being called with a random request code that does not match RequestCode.GPS_ENABLE.

Configuration

val isGooglePlayAvailable = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(Utils.getApp()) == ConnectionResult.SUCCESS

        val conf = LocationConfiguration.Builder()
            .askForPermission(
                PermissionConfiguration.Builder()
                    .rationaleMessage(StringUtils.getString(R.string.enable_location_rational_message))
                    .build()
            )

        return conf.also {
            if (isGooglePlayAvailable){
                it.useGooglePlayServices(
                    GooglePlayServicesConfiguration.Builder()
                        .failOnSettingsApiSuspended(true)
                        .build()
                )
            }else{
                it.useDefaultProviders(
                    DefaultProviderConfiguration.Builder()
                        .gpsMessage(StringUtils.getString(R.string.location_gps_message))
                        .build()
                )
            }
        }.build()