0

I have built an app using location detection to get the current location I am using LocationManager and LocationLiastener

the app works fine but when I tried to run it on advice without android play service it won't get the current Location and show the following dialog enter image description here

this is the app link on Github https://github.com/mostafa-n3ma/Pcm-helper1.0

  • [No, it's not](https://www.google.com/search?q=android+location+without+google+play+services&rlz=1C1CHBF_enUS989US989&oq=android+location+without+g&aqs=chrome.0.0i20i263i512j0i512j69i57j0i22i30l2j0i390l3.4670j0j1&sourceid=chrome&ie=UTF-8). You're using the wrong dependencies. – Gavin Wright Jun 10 '22 at 23:01
  • I am using it when I check whether the location settings are enabled or not by calling LocationRequest from that library so whenever I run it on a device with no google services the the Location Update request is not triggered I will use a different ways to check Location settings thanks... – مصطفى نعمه Jun 13 '22 at 05:36

2 Answers2

0

By checking your code here https://github.com/mostafa-n3ma/Pcm-helper1.0/blob/master/app/build.gradle#L69

Are you sure you are not dependent on the google play service library?

Ihor Bykov
  • 1,843
  • 3
  • 15
  • 22
  • sorry I am using the library when I check the Location Settings if the location is enabled or not and I will direct the user to enable it in the method checkDeviceLocationSettingsAndGetLocationUpdates() in the fragment that deals with current Location – مصطفى نعمه Jun 13 '22 at 05:17
0

this is the problem

    private fun checkDeviceLocationSettingsAndGetLocationUpdates(resolve: Boolean = true) {
    val locationRequest = com.google.android.gms.location.LocationRequest.create().apply {
        priority = LocationRequest.QUALITY_LOW_POWER
    }
    val builder = LocationSettingsRequest.Builder().addLocationRequest(locationRequest)

    val settingsClint = LocationServices.getSettingsClient(requireActivity())
    val locationSettingsResponseTask = settingsClint.checkLocationSettings(builder.build())

    locationSettingsResponseTask.addOnFailureListener { exeption ->
        if (exeption is ResolvableApiException && resolve) {
            try {
                startIntentSenderForResult(
                    exeption.resolution.intentSender,
                    REQUEST_TURN_DEVICE_LOCATION_ON,
                    null,
                    0, 0, 0,
                    null
                )
            } catch (sendEx: IntentSender.SendIntentException) {
                Log.d(TAG, "Error geting location settings resolution: " + sendEx.message)
            }
        } else {
            Snackbar.make(
                this.requireView(),
                "Location services must be enabled to use the app", Snackbar.LENGTH_INDEFINITE
            ).setAction(android.R.string.ok) {
                checkDeviceLocationSettingsAndGetLocationUpdates()
            }.show()
        }

    }

    locationSettingsResponseTask.addOnCompleteListener {
        if (it.isSuccessful) {
            locationManager.requestLocationUpdates(
                LocationManager.GPS_PROVIDER, 0, 0.0f, locationListener
            )

        }
    }
   

}

I am using the google services library to check Location setting if it was enabled or not if the location is ON the location update request will be triggered

else it will ask the user to enable it and then trigger the location update request

if the services are not available nothing will happen and no location update will be requested

so I will try another way to check the location feature

  • See [here](https://github.com/gavingt/SunCalculator/blob/8d99560ce6b4888488a1b500f7f3ab3193aaeef8/app/src/main/java/com/gavinsappcreations/sunrisesunsettimes/utilities/utils.kt#L99) for how to check whether location is enabled without Google Play Services. – Gavin Wright Jun 13 '22 at 05:46