Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Contributor
Posts: 13
Registered: ‎01-08-2013
My Device: Dev Alpha
My Carrier: Dev Alpha

Re: How to check if an App has "read_geolocation" Permission?

case 1 and 2 are fresh starts of the app.
And i've never seen geolocation_stop_events return a value different form -1.
BlackBerry Development Advisor
Posts: 68
Registered: ‎10-15-2012
My Device: Z10
My Carrier: Telus

Re: How to check if an App has "read_geolocation" Permission?

[ Edited ]

Hi,

 

As Curahee has mentioned, the link https://developer.blackberry.com/cascades/reference/qtmobilitysubset__qgeopositioninfosource.html has more information. The section about the replyErrorCode property describes how to detect fatal errors and warnings from within your slot that is connected to the QGeoPositionInfoSource::updateTimeout() signal. The replyErrorCode property is a BlackBerry extension to the Qt Mobility 1.2 QtLocation API. The Qt Mobility 1.2 QtLocation API has a provision for indicating a timeout has occurred but no information as to why. The replyErrorCode property gives you access to more information.

 

- Location Services is accessed by the user under Settings -> Location Services. If it is turned off, this immediately disables positioning information for all apps. Any apps using QGeoPositionInfoSource that are expecting updates will have their slot (connected to the QGeoPositionInfoSource::updateTimeout() signal) invoked. If the replyErrorCode property is queried in this slot it will have the value:

bb::location::PositionErrorCode::FatalDisabled

 

- Permissions are accessed by the user under Settings -> Security and Privacy -> Application Permissions. If the location permission is turned off for a given app this disables positioning information for the given app, and only affects the app the next time it requests positioning information. If the app is currently running, and is currently receiving position updates, it will not be affected. Note that this behaviour may change in the future. Currently, it may be safest to assume that the permission state for a given app is only guaranteed to take effect the next time it is started. In the 10.1 release there will be a new value for the replyErrorCode property:

bb::location::PositionErrorCode::FatalPermission

 This indicates that position updates failed because the app does not have location permission. Again, you should test for this in the slot connected to the QGeoPositionInfoSource::updateTimeout() signal.

 

When these fatal errors are encountered you should call QGeoPositionInfoSource::stopUpdates() (if startUpdates() was called), and can alert the user to the fact that the given setting is disabled. If your app has connected to the bb::cascades::Application fullscreen() signal, then in the connected slot you can attempt to restart position updates (making the assumption that the user enabled the required setting and is returning to your app). Or for Location Services, you can first query the locationServicesEnabled property on the QGeoPositionInfoSource to see if it has been turned on again before attempting to restart position updates.

 

Jim

Contributor
Posts: 13
Registered: ‎01-08-2013
My Device: Dev Alpha
My Carrier: Dev Alpha

Re: How to check if an App has "read_geolocation" Permission?

Hey Jim,

like i said before, the signal updateTimeout() will never occure if QGeoPositionInfoSource::requestUpdate() fails so i can't check for the error when permission is not granted.

I think the QGeoPositionInfoSource::createDefaultSource() should return 0 if the permission is not granted, like it is written in the docs: "Note: BB10 applications require the read_geolocation permission otherwise createDefaultSource() returns 0."
BlackBerry Development Advisor
Posts: 68
Registered: ‎10-15-2012
My Device: Z10
My Carrier: Telus

Re: How to check if an App has "read_geolocation" Permission?

Hi,

 

How do you know requestUpdate() fails? It is precisely by the emission of the updateTimeout() signal. After calling requestUpdate(), either the signal positionUpdated() is emitted or the signal updateTimeout() is emitted. If you are connected to these signals then the corresponding slot will be invoked. If there is an error then updateTimeout() is emitted, and you can test replyErrorCode in your timeout slot.

 

The documentation is inaccurate, what happens is that if the permission is not enabled then calling startUpdates() and requestUpdate() will result in the updateTimeout() signal being emitted, and the replyErrorCode being set accordingly. Sorry for the misunderstanding, I will get the documentation updated.

 

Jim

Contributor
Posts: 13
Registered: ‎01-08-2013
My Device: Dev Alpha
My Carrier: Dev Alpha

Re: How to check if an App has "read_geolocation" Permission?

I know that requestUpdate() fails, because i see a message in the console when starting the app from eclipse. "LocationManagerUtil.cpp:sendRequest(): error opening pps object, errno = 13 ( Permission denied ). Clients should verify that they have read_geolocation permission."

I've connected the timeout and update signals successfully and after that i started requestUpdate() with a timeout of 30000, waited 30 seconds and no signal was fired.
Highlighted
BlackBerry Development Advisor
Posts: 68
Registered: ‎10-15-2012
My Device: Z10
My Carrier: Telus

Re: How to check if an App has "read_geolocation" Permission?

Ah, I understand, sorry I didn't get it before. Are you testing on a 10.1 build? What I described was for 10.1. In 10.1 you should observe the timeout signal being emitted. In 10.0.9 there is a bug, if requestUpdate() fails due to permission no timeout is emitted. You should be able to work around this by calling startUpdates() instead. With startUpdates() the timeout will be called if there is a permission error (though you won't get any indication that it timed out because of permission).

 

You should be able to mimic requestUpdate() behaviour by setting a large update interval, and calling startUpdates(). Once you receive either signal (positionUpdated() or updateTimeout()) you can call stopUpdates(). If you want it to timeout after a certain period (like that passed to requestUpdate()) you can set the responseTime property on your QGeoPositionInfoSource instance:

 

source->setProperty( "responseTime", 10.0 ); // note the time is in seconds, unlike requestUpdate()

 

If your app is already calling startUpdates() for some reason, you can create a second position info source and use it to mimic requestUpdate().

 

Jim

Contributor
Posts: 13
Registered: ‎01-08-2013
My Device: Dev Alpha
My Carrier: Dev Alpha

Re: How to check if an App has "read_geolocation" Permission?

Yeah this gives me the informations i need.

Until 10.1 is available for Z10, i will use PositionErrorCode::None to estimate that Permission is not granted.

Thank you.
New Developer
Posts: 14
Registered: ‎02-20-2013
My Device: BB 10 Dev Alpha B
My Carrier: BB 10

Re: How to check if an App has "read_geolocation" Permission?

I have tried to set the response timeout property by calling

source->setProperty( "responseTime", 10.0 );

but while I build the solution it gives me the following error.

no matching function for call to 'QtMobilitySubset::QGeoPositionInfoSource::setProperty(const char [13], double)'   

 

I m not getting whats the error it is...
could you please help me in this regard.
Thanks.

BlackBerry Development Advisor
Posts: 68
Registered: ‎10-15-2012
My Device: Z10
My Carrier: Telus

Re: How to check if an App has "read_geolocation" Permission?

Hi,

 

Somehow you are trying to pass an array of const char instead of just a pointer to a const char (?) Does at least this work:

 

source->setProperty("responseTime", 10.0);

 

?

 

Can you show a code snippet if you can't figure it out?

 

Jim

 

New Developer
Posts: 14
Registered: ‎02-20-2013
My Device: BB 10 Dev Alpha B
My Carrier: BB 10

Re: How to check if an App has "read_geolocation" Permission?

Hello
Thanks for the quick reply. Follow is the code snippet...

m_positionSource = QGeoPositionInfoSource::createDefaultSource(this);

 

m_positionSource->setPreferredPositioningMethods(QGeoPositionInfoSource::NonSatellitePositioningMethods);

m_positionSource->setProperty("responseTime", 10.0);

 

bool isConnected = connect(m_positionSource, SIGNAL(positionUpdated(const QGeoPositionInfo &)), this, SLOT(positionUpdated(const QGeoPositionInfo &)));
   

bool isTimeOutConnected = connect(m_positionSource, SIGNAL(updateTimeout()), this, SLOT(positionUpdateTimeout()));

 

if (isConnected)
        m_positionSource->requestUpdate();

 

on building the project it gives the error

no matching function for call to 'QtMobilitySubset::QGeoPositionInfoSource::setProperty(const char [13], double)'

 

 

Thanks

Faheem