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

Java Development

Reply
Developer
Posts: 551
Registered: ‎10-31-2009
My Device: Torch 9800, Bold 9700
My Carrier: Movistar, Telenor

Setting permissions

The API has functions for working with permissions. I am not fully clear on how it is supposed to work

 

I have listeners for phone phonelog and global events and a few other modules that needs to have permissions. When new modules are loaded there is a sequence of going into applicatios, permissions and setting a number of "allows".

 

So I wrote this little class that these modules calls:

 

public String checkAndSet(int key,String id)
 {
   String message;
   int _allow;
   _allow = perms.VALUE_ALLOW;
   if(perms.containsPermissionKey(key))              //There is a key
     {
       if(perms.getPermission(key)!= _allow)     //But its not set to Allow
        {
         comm.HandleAlert(settings.Debug,"checkPermissions: Trying to change permission "+id ,0);   //Try to change it
         perms.addPermission(key);  
        }
     }
    else                                             //There is no key,  try to add with value Allow
     {
       comm.HandleAlert(settings.Debug,"checkPermissions: Trying to set permission "+id ,0);
       perms.addPermission(key);    
     }
   if(perms.getPermission(key) != _allow)            //Nope
    {
      comm.HandleAlert(settings.Debug,"checkPermissions: could not change or set permission "+id,1 );
      return "Fail";
    }
   return "";
 }

 

the meesages I get when debuggin is:

 

2010-08-11 10:45:26 checkPermissions: Trying to set permission Input simulation
2010-08-11 10:45:26 checkPermissions: Trying to set permission Internet
2010-08-11 10:45:26 checkPermissions: Trying to set permission Cross App Comm.
2010-08-11 10:45:26 checkPermissions: Trying to set permission File API
2010-08-11 10:45:26 checkPermissions: Trying to set permission Phone

 

This seems to indicate that everytthing worked ok, but I still get prompts on the phone.

 

On the other hand it seems a bit funny that it should be possible to just set everything  to allow without user intervention.

 

Must be something I am missing here.

If everything seems to be under control, you're just not driving fast enough
-Mario Andretti-
Regular Contributor
Posts: 71
Registered: ‎07-11-2010
My Device: Bold 9000
My Carrier: none

Re: Setting permissions

you need to call

 

ApplicationPermissionsManager.getInstance().invokePermissionsRequest(permissions);



It will display a couple of system dialogs to  the user, allowing her to change permissions (if she wants to)

 

example code:

 

 

ApplicationPermissions permissions = new ApplicationPermissions();
permissions.addPermission(ApplicationPermissions.PERMISSION_FILE_API);
permissions.addPermission(ApplicationPermissions.PERMISSION_CROSS_APPLICATION_COMMUNICATION);
permissions.addPermission(ApplicationPermissions.PERMISSION_DEVICE_SETTINGS);
permissions.addPermission(ApplicationPermissions.PERMISSION_APPLICATION_MANAGEMENT);
....

res = ApplicationPermissionsManager.getInstance().invokePermissionsRequest(permissions);

if (res)
{
  // got them
}
else
{
  // rejected
}

 

 


-----
A good decision is based on knowledge and not on numbers.
Developer
Posts: 551
Registered: ‎10-31-2009
My Device: Torch 9800, Bold 9700
My Carrier: Movistar, Telenor

Re: Setting permissions

I see, thanks. will try it soon

If everything seems to be under control, you're just not driving fast enough
-Mario Andretti-