Display custom messages in the request permission dialog

by BlackBerry Development Advisor on ‎02-16-2010 10:16 AM (2,683 Views)

Summary


This article applies to the following:

  • BlackBerry® Device Software 4.5 and later
  • BlackBerry® Java® Development Environment (BlackBerry JDE) 4.5 and later


Details


If you want to display custom messages when your application prompts the BlackBerry smartphone user for particular permissions, you can use the net.rim.device.api.applicationcontrol.ReasonProvider interface.


Below is an example of using the ReasonProvider interface to show a custom message for the Event Injection request permission dialog and a generic message for all other request permission dialogs.


import net.rim.device.api.applicationcontrol.*;
import net.rim.device.api.system.*;
import net.rim.device.api.ui.Keypad;

public class Main extends Application {

   private static Main myApp;

   public static void main(String[] args) {
      myApp = new Main();
      myApp.enterEventDispatcher();
   }

   public Main() {
      ApplicationPermissionsManager oAppPermManager = ApplicationPermissionsManager.getInstance();
      MyReasonProvider oMyReasonPrvdr = new MyReasonProvider();
      oAppPermManager.addReasonProvider(ApplicationDescriptor.currentApplicationDescriptor(), oMyReasonPrvdr);

      //Inject some keys to trigger the application permissions dialog.
      EventInjector.KeyCodeEvent oEventInjector = new EventInjector.KeyCodeEvent(EventInjector.KeyCodeEvent.KEY_DOWN,(char) Keypad.KEY_VOLUME_DOWN,0);
      EventInjector.invokeEvent(oEventInjector);

   }

   private class MyReasonProvider implements ReasonProvider {

      public String getMessage(int permissionID) {
         if (permissionID == ApplicationPermissions.PERMISSION_EVENT_INJECTOR) {
            return "Event Injection permission message.";
         } else {
            return "All other permissions message.";
         }
      }

   }
}

 


Note: The message will be viewable from a link in the request permissions dialog. The user will have to click this link to see your custom message.