Forums

OverviewFelgo 2 Support (Qt 5) › PositionResource permissions problems

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #23554

    jrrobles79

    I have been wasting a lot of time trying to make the permission for location work correctly, apparently I need to restart my app after I give the permissions, I don’t know how to make it ‘clean’ or transparent for the user, after I give the permissions I got this errors:

    [SplashPage].location perms enabled
    PositionSource: unknown source error
    [MainItem].[PositionSource].onActiveChanged:true
    PositionSource: closed error

     

    what Im doing wrong?

    on SplashPage.qml

    Component.onCompleted: {
    //this function check if there are any location permission using Android extras libraries
    // if there aren't the app request permissions and wait until the user choose, this triggers: onPermResult
    // if there are permits, trigger onPermResult,  no problems here.
    
    androidPerms.requestFineLocationPermission() 
    }
    
    Perm.Permissions{
    id: androidPerms
    onPermResult: {
    if(permRes){ 
    console.debug("[SplashPage].location perms enabled") 
    // the problem is the pos service is not starting as expected, only when I restart the app, after permissions were given.
    
    posSrc.start()
    
    }else{
    grantLocationPopUp.open() //this just show a warning to set ask for localization permissions for the app to work
    resetButton()
    }
    }
    
    }
    

     

     

    posService:

    PositionSource {
            id: posSrc
            updateInterval: constants.posUpdateInterval
            active: false //false as default, active after permissions are granted
            signal hasError() //trigger on error has occurred
            signal coordFetched() //triggerd after the position has changed
            property var coord. //value that stores the coordinates
            property bool printPos: true //just a value to print pos only once on the console
    
            onActiveChanged: {
                console.debug( "[MainItem].[PositionSource].onActiveChanged:" +posSrc.active )           
            }
    
            onPositionChanged: {
                console.debug( "[MainItem].[onPositionChanged]")
                if (!posSrc.active) {
                    console.debug( "[MainItem].[onPositionChanged].pos not active")
                    return
                }
    
                if(posSrc.printPos){
                    console.debug("*******[POS CHANGED]********")
                    console.debug("pos_active:" + posSrc.active)
                    console.debug("pos_valid:" + posSrc.valid)
                    console.debug("lon:" + posSrc.position.coordinate.longitude)
                    console.debug("lat:" + posSrc.position.coordinate.latitude)
                    console.debug("****************************")
                    posSrc.printPos = false
                }
    
                coord = posSrc.position.coordinate
                var lonlat = models.getLonLat( posSrc.position.coordinate.longitude , posSrc.position.coordinate.latitude  )
                app.settings.setValue( properties.mCOORDINATES , lonlat )
                coordFetched()
                console.debug("[MainItem].[onPositionChanged].finish")
            }
    
            onSourceErrorChanged: {                       
                var error = false;
                switch(sourceError){
                    case PositionSource.AccessError:
                        console.error("PositionSource: access error")
                        error = true
                        break;
    
                    case PositionSource.ClosedError:
                        console.error("PositionSource: closed error")
                        error = true
                        break;
    
                    case PositionSource.UnknownSourceError:
                        console.error("PositionSource: unknown source error")
                        error = true
                        break;
    
                    case PositionSource.SocketError:
                        console.error("PositionSource:  socket error")
                        error = true
                        break;
    
                    case PositionSource.NoError:
                    default:
                        console.debug("pos ok")
                        break;
                }
    
                if( error){
                    app.settings.setValue( properties.mCOORDINATES,   models.getLonLat(0, 0) )
                    app.settings.setValue( properties.mZONE, models.getEmptyZone() )
                    hasError()
                }
            }
        }

     

     

     

    #23585

    Alex
    Felgo Team

    Hi,

    this is an Qt issue that you can avoid by requesting the permission on Android already from C++, e.g. in your main.cpp right after engine.load(…), like this:

    #ifdef Q_OS_ANDROID
      QtAndroid::PermissionResult r = QtAndroid::checkPermission("android.permission.ACCESS_FINE_LOCATION");
      if(r == QtAndroid::PermissionResult::Denied) {
        QtAndroid::requestPermissionsSync( QStringList() < < "android.permission.ACCESS_FINE_LOCATION" );
        r = QtAndroid::checkPermission("android.permission.ACCESS_FINE_LOCATION");
        if(r == QtAndroid::PermissionResult::Denied) {
    //         return false;
        }
       }
    //   return true;
      #endif

    This requires you to also add this to your pro file:

    android {
      QT += androidextras
    }
    

    Best,
    Alex

    #23592

    jrrobles79

    Hi Alex, thank you for your answer, but this works partially, when Im on the felgo live configuration, it does works, but as soon I set the main.cpp and .pro to create the apk , is the same behavior, the pos only works as soon as I restart the app, but if I install the app and grant location permissions, the pos is giving me this error:

    PositionSource: unknown source error

     

    I have necessarily to restart the app, and thats something that I don’t want, I need that the app works as soon I grant locations permits

Viewing 3 posts - 1 through 3 (of 3 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support