mrmans0n / smart-location-lib

Android library project that lets you manage the location updates to be as painless as possible
1.65k stars 353 forks source link

Add google location dialog #212

Open danponce opened 7 years ago

danponce commented 7 years ago

This library is great! It simplifies a lot the code for getting locations, so thanks! Now, to show the dialog (same as the Google Maps dialog) that turns the GPS on, the library needs to use LocationSettingsRequest.Builder and use the method setAlwaysShow(true). Can you add this option please?

saeedjassani commented 7 years ago

@mrmans0n It would be really helpful if you add this option too.. Thanks in advance

putrabangga commented 6 years ago

+1

araiyusuke commented 6 years ago

That option is provided.

provider = new LocationGooglePlayServicesProvider(); provider.setCheckLocationSettings(true);

Ornolfr commented 6 years ago

@araiyusuke thanks for your suggestion, it shows the dialog indeed. But the location itself is not fetched, the callback is not fired. Here is my code:

SmartLocation
                .with(this)
                .location(LocationGooglePlayServicesProvider().apply { setCheckLocationSettings(true) })
                .start {
            Timber.e(it.toString())
        }

If GPS is already enabled and it doesn't need to show the dialog, it works normally. Any info on that?

luthfihariz commented 5 years ago

@araiyusuke thanks for your suggestion, it shows the dialog indeed. But the location itself is not fetched, the callback is not fired. Here is my code:

SmartLocation
                .with(this)
                .location(LocationGooglePlayServicesProvider().apply { setCheckLocationSettings(true) })
                .start {
            Timber.e(it.toString())
        }

If GPS is already enabled and it doesn't need to show the dialog, it works normally. Any info on that?

Hey I was experiencing the same problem, but then found out the solution. It's there in the log, saying that you will get your callback in your Activity's callback. Then you need to call the provider's onActivityResult to continue the flow or probably just start requesting location again.

LocationGooglePlayServicesProvider.this.logger.w("Location settings are not satisfied. Show the user a dialog to upgrade location settings. You should hook into the Activity onActivityResult and call this provider's onActivityResult method for continuing this call flow. ", new Object[0]);

RazibKani commented 5 years ago

Basically you can not show Location Settings if not init SmartLocation using Activity Context, because the Dialog only show if context is instance of Activity as shown below..

if (context instanceof Activity) { try { // Show the dialog by calling startResolutionForResult(), and check the result // in onActivityResult(). status.startResolutionForResult((Activity) context, REQUEST_CHECK_SETTINGS); } catch (IntentSender.SendIntentException e) { logger.i("PendingIntent unable to execute request."); } } else { logger.w("Provided context is not the context of an activity, therefore we can't launch the resolution activity."); }

This snippet from https://github.com/mrmans0n/smart-location-lib/blob/master/library/src/main/java/io/nlopez/smartlocation/location/providers/LocationGooglePlayServicesProvider.java