Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
315 views
in Technique[技术] by (71.8m points)

android - Windev Mobile 25 - Unable to access GPS / Device location after selecting "Allow Only While In Use" Permission

I have an app that has been working up until this point. Recently upgraded to WM 25, target SDK is 29 and currently testing on a Pixel 3a with Android 11. The app is currently unable to access the device's location unless you select "Allow all the time" which I do not want. Selecting "While using the app" ends up causing an issue and the app freezes, if you completely close out the app and change the permissions in the app settings to "Allow all the time" and restart the app - within 2 seconds I am seeing the device location on the main screen. The goal is to just allow the app to access the device location while the app is in use but everything I have read does not give me any indication as to what is wrong?

Currently using GPSFollowMovement, GPS Status and GPSInitParameter functions in my WLanguage code (below).

Also have ACCESS_COURSE_LOCATION, ACCESS_FINE_LOCATION and ACCESS_BACKGROUND_LOCATION permissions in my app manifest.

Nothing seems to be working as the first permission request reads

This app may want to access your location all the time, even when you're not using the app

  • While using the app
  • Only at this time
  • Deny

A second window appears that reads

Change location access for app? This app wants to access your location all the time, even when you're not using the app.

  • Keep "While the app is in use"

PROCEDURE Start_GPS()

GPSInitParameter(gpsAuto, gpsPrecisionHigh)

// Check the GPS
IF GPSStatus() = gpsDisabled THEN
    Info("Please enable the GPS in your phone settings.")
ELSE
    _ChangeGPSStatus(GPSStatus())
END

// Callback procedure for detecting the change of GPS status
GPSStatus(_ChangeGPSStatus)

PROCEDURE _ChangeGPSStatus(nStatus)

SWITCH nStatus
    CASE gpsEnabled // the provider was enabled by the user.
        EXPRESS_WIN_MAIN.STC_GPSStatus = "GPS Enabled"
        // Asks to follow the move with a maximum time between two calls to 
        GPSFollowMovement(_GetPosition,1000)
    CASE gpsDisabled // the provider was disabled by the user.
        EXPRESS_WIN_MAIN.STC_GPSStatus= "GPS Disabled"
    CASE gpsOffService // the provider is off service.
        EXPRESS_WIN_MAIN.STC_GPSStatus = "GPS off service"
    CASE gpsUnavailable // the provider is temporarily unavailable.
        EXPRESS_WIN_MAIN.STC_GPSStatus = "GPS Unavailable"
    CASE gpsAvailable // the provider is available.
        EXPRESS_WIN_MAIN.STC_GPSStatus = "GPS Available" 
        GPSFollowMovement(_GetPosition,1000)
END

PROCEDURE _GetPosition(MyPosition is a geoPosition)

// Update the information about the position
// Latitude and longitude
grCurrentLatitude = MyPosition..Latitude
grCurrentLongitude = MyPosition..Longitude

IF MyPosition..PrecisionValid THEN
    grCurrentGPSAccuracy = MyPosition..Precision
ELSE
    grCurrentGPSAccuracy = -1.0  //default value for unknown precision
END

//IF CurrentWin() ~= "EXPRESS_WIN_MAIN" THEN

IF grCurrentLatitude > 0 THEN
    EXPRESS_WIN_MAIN.STC_Latitude = NumToString(grCurrentLatitude, "3.4f")  + "° (N)" 
END
IF grCurrentLongitude < 0 THEN
    EXPRESS_WIN_MAIN.STC_Longitude = NumToString(grCurrentLongitude, "+3.4f")  + "° (W)" 
END
IF grCurrentGPSAccuracy > 0 THEN
    EXPRESS_WIN_MAIN.STC_GPSAccuracy = NumToString(grCurrentGPSAccuracy / 0.3048, "+5.1f")  + " ft" 
ELSE
    EXPRESS_WIN_MAIN.STC_GPSAccuracy = "Unknown"
END

    
//ELSE 
//IF CurrentWin() ~= "EXPRESS_WIN_REPORT" THEN
    WHEN EXCEPTION IN
        IF grCurrentLatitude > 0 THEN
            EXPRESS_WIN_REPORT.STC_Latitude = NumToString(grCurrentLatitude, "3.4f")  + "° (N)" 
        END
        IF grCurrentLongitude < 0 THEN
            EXPRESS_WIN_REPORT.STC_Longitude = NumToString(grCurrentLongitude, "+3.4f")  + "° (W)" 
        END
        IF grCurrentGPSAccuracy > 0 THEN
            EXPRESS_WIN_REPORT.STC_GPSAccuracy = NumToString(grCurrentGPSAccuracy / 0.3048, "+5.1f")  + " ft" 
        ELSE
            EXPRESS_WIN_REPORT.STC_GPSAccuracy = "Unknown"
        END
    DO
        //for some reason when closing EXPRESS_WIN_REPORT, after landing in EXPRESS_WIN_DETAILS, still gets through the IF and gives an error
    END
question from:https://stackoverflow.com/questions/65833393/windev-mobile-25-unable-to-access-gps-device-location-after-selecting-allow

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...