android / location-samples

Multiple samples showing the best practices in location APIs on Android.
Apache License 2.0
2.7k stars 2.78k forks source link

Geofencing sample is still targeting sdk 28 #200

Open BhavyaRattan opened 5 years ago

BhavyaRattan commented 5 years ago

Geofencing sample is still targeting sdk 28: Will Geofences work in the same after targeting Android Q or are there any changes to be made?

ghost commented 5 years ago

I don't think there is anything to change considering this basic Geo-fencing demo when targeting sdk version 29. Have you tried running by changing the sdk from 28 to 29 and running it on a Android Q device or emulator ? Are you facing any issues ?

BhavyaRattan commented 5 years ago

Yes I tried running by changing sdk from 28 to 29 on an Android Q emulator, the issue there is that Geofencing requires BACKGROUND_LOCATION which is not currently handled in this repo. So you do not get any geofences triggered and the user doesn't even get to know why so. It should be handled in a similar way like the locationupdatespendingintent sample in this repo.

ghost commented 5 years ago

Have you tried following the docs on Change location settings

I don't think it's sdk issue. This demo supresses missing permission warning using the @SuppressWarnings("MissingPermission") assuming user will grant these permission manually either opening some other similar app like google maps or accepting location permission by going to app settings itself.

You have to implement location settings yourself for this demo. Check out the MainActivity.java from locationupdatespendingintent and implement the following functions either copy pasting or writing yourself

  1. checkPermissions()
  2. rquestPermissions()
  3. onRequestPermissionsResult()

The check the onCreate() function and see how these function are called.

onRequestPermissionsResult() will be called by the system when user either accept or reject the location permission prompt.

pramodit commented 5 years ago

Hey @BhavyaRattan , It works with the JobScheduler API

Refer this - https://github.com/googlesamples/android-play-location/issues/197