PC SOFT

GRUPOS DE DISCUSSÃO PROFISSIONAL
WINDEVWEBDEV e WINDEV Mobile

Inicio → WINDEV Mobile 25 → Android GPS / Location Help
Android GPS / Location Help
Iniciado por Claire, jan., 13 2021 10:46 PM - 8 respostas
Membro registado
45 mensagems
Publicado em janeiro, 13 2021 - 10:46 PM
I have a question regarding permissions and getting the GPS location for an Android device.

Device: Pixel 3a
OS: Android 11

My app seems to be working as it should except for being able to get the device location. When the app initially starts I receive a pop up message that asks "Allow app to access this device's location" I select "While using the app" and then get asked again if I would like to change the location access for the app (pictures attached).









GPS does not seem to work with "while using the app" selected - it will freeze the app on the main screen (where location is displayed) and I have to completely close down the app. As soon as I go into the app settings and select "Allow all the time" the app works just fine with no errors.





Is there something that has changed, code wise, that would be causing this or does it have to do with permissions? I have background permissions granted. I would at least like to have the GPS work with "while using the app" is selected.
Membro registado
45 mensagems
Publicado em janeiro, 15 2021 - 4:19 PM
Can anyone assist with this? I can't seem to find any information about this issue.

is adding <service android:name="ForegroundService" android:foregroundServiceType="location"/> to the manifest necessary or does this interfere with the background services?
Publicado em janeiro, 15 2021 - 7:50 PM
There are two ways of accessing the GPS data... one is directly asking for the position when you need it, and the other is to have an event sent to you when the position changes (ie having the gps function run in the background)

If you are using that second system, then I suppose that android consider it to be a background function running all the time, and that, in order to make it work in new android versions, you have to choose the 'allow in settings' option to authorize access all the time...

If I'm correct, and it's easy to test by using the link in question, then your choice is between asking your users for that authorization of changing the way you are asking for the position
Membro registado
45 mensagems
Publicado em janeiro, 15 2021 - 10:34 PM
Argus wrote:
There are two ways of accessing the GPS data... one is directly asking for the position when you need it, and the other is to have an event sent to you when the position changes (ie having the gps function run in the background)

If you are using that second system, then I suppose that android consider it to be a background function running all the time, and that, in order to make it work in new android versions, you have to choose the 'allow in settings' option to authorize access all the time...

If I'm correct, and it's easy to test by using the link in question, then your choice is between asking your users for that authorization of changing the way you are asking for the position


Hi Argus, thank you for your reply.

I guess I don't know exactly how we are using it (I didn't write the app and there isn't a lot of notes in the code). I have the permissions set to allow ACCESS_BACKGROUND_LOCATION, ACCESS_COARSE_LOCATION, and ACCESS_FINE_LOCATION so I am confused as to why selecting "while using the app" would cause it to not work unless it is because it is maybe asking for both foreground and background at the same time? I am unable to remove ACCESS_BACKGROUND_LOCATION from the manifest because we have GPSFollowMovement, GPSInitParameter and GPSStatus in our code and I am not entirely sure I understand what needs to be re-worked.
Publicado em janeiro, 16 2021 - 3:19 PM
GPSFollowMovement.... therefore background...

So, first, you need to check that my analysis is correct by giving the authorization as described in my previous message

Then, if it DOES work that way, you have to decide... Either stop using the GPSFollowMovement function, or tell your users to give the FULL authorization
Membro registado
45 mensagems
Publicado em janeiro, 18 2021 - 2:38 PM
Argus wrote:
GPSFollowMovement.... therefore background...

So, first, you need to check that my analysis is correct by giving the authorization as described in my previous message

Then, if it DOES work that way, you have to decide... Either stop using the GPSFollowMovement function, or tell your users to give the FULL authorization


Hi Argus, thank you for the clarification. I appreciate it! Understood.
Membro registado
45 mensagems
Publicado em janeiro, 18 2021 - 5:22 PM
Argus wrote:
GPSFollowMovement.... therefore background...

So, first, you need to check that my analysis is correct by giving the authorization as described in my previous message

Then, if it DOES work that way, you have to decide... Either stop using the GPSFollowMovement function, or tell your users to give the FULL authorization


Hi Argus,

I have another question for you. Is there a way to edit the text that appears in the message asking to allow location access so that I can inform users that "Allow all the time" needs to be selected in order for the app to properly work?

I dug into the code a bit more and really went through the process and I believe that the app requires the location all the time so that it can keep the device location up to date. I tried changing GPSFollowMovement to GPSGetPosition and that did not change anything as they both require the background permission - it looks like anything that requires the devices' current location needs full access? What the app does is periodically check to make sure that the displayed GPS coordinates are up to date - not sure if there is another method for going about this to avoid the full location access?
Membro registado
45 mensagems
Publicado em janeiro, 18 2021 - 5:23 PM
Forgot to mention, I also commented out the line where GPSFollowMovement is used and the app still froze and would not bring back coordinates.
Membro registado
45 mensagems
Publicado em janeiro, 18 2021 - 6:02 PM
Apologies for all the messages but the end goal is to allow for the GPS to work only while the app is in use and that would require a lot of modification to the code I am assuming seeing that most of the GPS functions require background access?