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
New Developer
cippyboy
Posts: 17
Registered: ‎04-14-2013
My Device: Simulator

How to check for permissions at run-time ?

 

How do I check for permissions at run-time in a native app ?

 

Sometimes, when something (like say the ads service) requires permissions, you get a pop-up and you have the option to uncheck them. The ads don't work if I don't tick the device identifier info, so I'd like a way to check if certain permissions are currently available as a user can then go to settings->security and disable/enable permissions whenever he wants, so It would be nice to check those permissions before I start requesting ads (and crashing with it). He may not even know that the app crashes because of the lack of this permission :smileyindifferent:

--------------------------------------------------------------------------
www.facebook.com/relativegames - My Apps
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

Re: How to check for permissions at run-time ?

There's no API to check, so you have to discover it indirectly, generally by attempting the operation involved and catching any errors. For example, if they don't grant the "identifying info" permission, you'll get back something like 0000000 for the PIN.

As a result, each permission requires its own unique way of checking.

There should be an open feature request asking for improvements but I don't know what number it is offhand, and there's likely been no status update for quite some time. If they add it, it will probably be post-10.2.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
Innovatology
Posts: 1,280
Registered: ‎03-03-2011
My Device: Playbook, Z10, Q10, Z30 with Files & Folders and Orbit of course

Re: How to check for permissions at run-time ?

https://www.blackberry.com/jira/browse/TABLET-289

Files & Folders, the unified file & cloud manager for PlayBook and BB10 with SkyDrive, SugarSync, Box, Dropbox, Google Drive, Google Docs. Free 3-day trial! - Jon Webb - Innovatology - Utrecht, Netherlands
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

Re: How to check for permissions at run-time ?

Thanks Jon. I wonder if that's still got any visibility, given that it's "TABLET" and not "BB10". Always nice to have the original issue reporter step in with a link to the issue though. ;-)

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
Innovatology
Posts: 1,280
Registered: ‎03-03-2011
My Device: Playbook, Z10, Q10, Z30 with Files & Folders and Orbit of course

Re: How to check for permissions at run-time ?

I often wonder whether JIRA is any use at all. Many of my reported issues just ping-pong between Investigating and Triage every month or two.

Files & Folders, the unified file & cloud manager for PlayBook and BB10 with SkyDrive, SugarSync, Box, Dropbox, Google Drive, Google Docs. Free 3-day trial! - Jon Webb - Innovatology - Utrecht, Netherlands
New Developer
cippyboy
Posts: 17
Registered: ‎04-14-2013
My Device: Simulator

Re: How to check for permissions at run-time ?

[ Edited ]

 

Thanks for the info. After a bit more debugging, It seems I don't even need to get the actual PIN for the deviceinfo permission, but just to call one function. Here's the code I currently use :

 

 

#include <bps/deviceinfo.h>

 

deviceinfo_identifying_details_t *info = NULL;

bool HasDeviceInfoPermission = false;
    if (deviceinfo_get_identifying_details( &info ) == BPS_SUCCESS)
    {
        HasDeviceInfoPermission = true;
        if (info)
        {
            deviceinfo_free_identifying_details( &info );
        }
    }

 

I tested with and without the permission granted and it seems to work on the simulator, I do hope though that the device works the same. This only fixes the device info but hey, at least the ads code doesn't crash anymore :smileyhappy:

--------------------------------------------------------------------------
www.facebook.com/relativegames - My Apps