Solution
Solution

Reputation: 602

How to set orientation in blackberry java in phonegap?

I am developing a BlackBerry Java Phonegap application and i want to set the orientation of an application to portrait.

How to set orientation of application in BB Java using Phonegap?

Is there any way we can directly lock the orientation of BB Java Phonegap application using the BlackBerry app descriptor file?

Upvotes: 1

Views: 226

Answers (1)

Nate
Nate

Reputation: 31045

Option One

From BlackBerry Support Forums:

<rim:orientation mode="portrait" />

in your config.xml. Requires WebWorks SDK 2.3 or later.

Option Two

From tneil on supportforums.blackberry.com:

You can make a very small change to the WebWorks template files to accomplish this. However these changes will affect all WebWorks apps that you package with the WebWorks SDK unless you remove the changes later from the templates.

WARNING: Please make a back-up copy of your "device_templates" directory before performing the below actions.

Step 1) Browse to the "device_templates" directory of your BlackBerry WebWorks SDK. This directory is typically found in "[DRIVE]:\InstallDir\BlackBerry WebWorks Packager\device_templates"

Step 2) Open up the "Widget.java" file found in this directory in a text editor.

Step 3) Make the below changes in the Widget.java file. The changed lines of code are highlighted below:

public Widget(WidgetConfig wConfig) {
    _wConfig = wConfig;
    initialize();

    int directions = net.rim.device.api.system.Display.DIRECTION_PORTRAIT;   
    net.rim.device.api.ui.Ui.getUiEngineInstance().setAcceptableDirections(directions);

    // Create PageManager
    PageManager pageManager = new PageManager(this, (WidgetConfigImpl) _wConfig);

    // push screen
    WidgetScreen wScreen = new BrowserFieldScreen(this, pageManager);
    pageManager.pushScreens((BrowserFieldScreen)wScreen);
}    

Step 5) Run your app and enjoy the cool locked orientation :)

The direction you wish to lock your screen to is set on the "directions" local variable. This value can be one of the following:

  • net.rim.device.api.system.Display.DIRECTION_NORTH
  • net.rim.device.api.system.Display.DIRECTION_SOUTH
  • net.rim.device.api.system.Display.DIRECTION_EAST
  • net.rim.device.api.system.Display.DIRECTION_WEST
  • net.rim.device.api.system.Display.DIRECTION_LANDSCAPE
  • net.rim.device.api.system.Display.DIRECTION_PORTRAIT

  • net.rim.device.api.system.Display.DIRECTION_NORTH

  • net.rim.device.api.system.Display.DIRECTION_SOUTH
  • net.rim.device.api.system.Display.DIRECTION_EAST
  • net.rim.device.api.system.Display.DIRECTION_WEST
  • net.rim.device.api.system.Display.DIRECTION_LANDSCAPE
  • net.rim.device.api.system.Display.DIRECTION_PORTRAIT

Non-Storm/Torch devices will ignore this flag.

Upvotes: 1

Related Questions