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
torsten_ktz
Posts: 13
Registered: ‎01-08-2013
My Device: Dev Alpha
My Carrier: Dev Alpha
Accepted Solution

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

Hello all,

 

i'm using QGeoPositionInfoSource::createDefaultSource() to get a PositionInfoSource.

If the user has revoked the permisson for "read_geolocation", a call to PositionInfo::requestUpdate() will fail with an error in console.

 

I get no signals if this happens and i haven't found a way to check if the permission is granted.

 

Maybe somone knows a solution for this problem.

 

Thanks.

Please use plain text.
Developer
zezke
Posts: 1,004
Registered: ‎12-12-2010
My Device: Z10 (red Limited Edition)
My Carrier: Mobile Vikings

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

Can you catch this error somehow?
-------------------------------------------
BlackBerry Certified Builder for Native Application Development -- Proud member of the Belgian BlackBerry Developer group
Samples: Park in Ghent
Feeling generous? Nominate me for BB Elite member!
Please use plain text.
Contributor
torsten_ktz
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?

Hi zezke,

i think i can't.

The API says: "Note: BB10 applications require the read_geolocation permission otherwise createDefaultSource() returns 0."
But it returns a valid PositionInfoSource no matter if the permission is granted or not. The only error i get is an output in console, but nothing i could check in the code.
Please use plain text.
Developer
Curahee
Posts: 210
Registered: ‎01-12-2013
My Device: z30
My Carrier: Mobile Vikings

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

[ Edited ]

I found this check in the API

 

if ( !positionInfoSource->property("locationServicesEnabled").toBool() ) {

}

 You can find more at this link

https://developer.blackberry.com/cascades/reference/qtmobilitysubset__qgeopositioninfosource.html

 

You can use Ctrl+F and search for 'locationServicesEnabled'. You can find some more info about that property.

______________________________________________________
beRail: BlackBerry World - GitHub
Mobile Vikings: BlackBerry World - GitHub
Park in Brussels: BlackBerry World
Please use plain text.
Contributor
torsten_ktz
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?

Hi Curahee,

this property tells you if Location Services are enabled. But the bool will not be false if the permission is not granted.
Please use plain text.
New Contributor
ardiri
Posts: 6
Registered: ‎02-15-2013
My Device: Z10
My Carrier: Telekom.de

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

[ Edited ]

http://developer.blackberry.com/native/reference/bb10/com.qnx.doc.bps.lib_ref/com.qnx.doc.bps.lib_re...

 

The geolocation_request_events() function starts to deliver geolocation change events to your application using BPS. If the application does not have the read_geolocation capability, this function will fail. Events will be posted to the currently active channel.

 

so the following code should do it:

 

int geolocation_enabled = 0;

 

{

  int err = geolocation_request_events(0);

  geolocation_stop_events(0);

 

  // based on the request; flag if it has been enabled or not.

  if (err == BPS_SUCCESS) geolocation_enabled = 1; 

}

 

this should do exactly what you need.

 

// Aaron Ardiri
Please use plain text.
Contributor
torsten_ktz
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?

Hi ardiri,

thanks for your answer.

Your solution works only once.
If the permission is granted when i use geolocation_request_events(0) the first time and the user revokes it afterwards, a second call to geolocation_request_events(0) will return no error.

I think the problem is that geolocation_stop_events(0) does not work correctly. This call always returns -1.
Please use plain text.
New Contributor
ardiri
Posts: 6
Registered: ‎02-15-2013
My Device: Z10
My Carrier: Telekom.de

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

could it be that the geolocation_stop_events() messes up the BPS sub-system when called on failure? :smileyhappy:

 

int geolocation_enabled = 0;

 

{

  int err = geolocation_request_events(0);

 

  // based on the request; flag if it has been enabled or not.

  if (err == BPS_SUCCESS)

  {

    geolocation_enabled = 1; 

    geolocation_stop_events(0);

  }

}

 

would that make a difference? :smileyhappy: you should never call geolocation_stop_events() if the first failed.  alternatively; the documentation states that if the permission isn't available there either.. it'll fail. you could simplify the whole process down to:

 

int geolocation_enabled = 0;

 

{

  int err = geolocation_stop_events(0);

 

  // based on the request; flag if it has been enabled or not.

  if (err == BPS_SUCCESS) geolocation_enabled = 1; 

}

 

of course; this could be a complete underlying issue altogether and a bug in the way these are handled. if you could verify; that would be great and if it is a bug, a PR/bug report can be filed documenting that this isn't working as it should be. 

// Aaron Ardiri
Please use plain text.
Contributor
torsten_ktz
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?

[ Edited ]

int geoAllowed = 0;
{
    int err1 = geolocation_request_events(0);
   LOG << "1: " << err1 << LOG_EOL;
   if(err1 == BPS_SUCCESS)
   {
      geoAllowed = 1;
      int err2 = geolocation_stop_events(0);
      LOG << "2: " << err2 << LOG_EOL;
   }
}

 

case 1: Start with permission granted

OUTPUT:
1: 0
2: -1

Revoke permission

OUTPUT:
1: 0
2: -1

 

case 2: Start with permission revoked

OUTPUT:
1: -1

Grant permission

OUTPUT:
1: 0
2: -1

 

geolocation_stop_events always returns -1.

if a call to geolocation_request_events was successfull, it seems to always return SUCESS.

Please use plain text.
New Contributor
ardiri
Posts: 6
Registered: ‎02-15-2013
My Device: Z10
My Carrier: Telekom.de

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

so it is clear that it geolocation_request_events(0) only returns an error once; if the permission is not granted.. was this with subsequent runs or during the same execution process? it could be that the value is cached and hence any subsequent calls to the function doesn't check to see if the permission has been revoked while the process is actually running - if that is the case; it is a bug and a bug report should be generated.

// Aaron Ardiri
Please use plain text.