0

Doing an cordova app with angularjs as the frontend framework. I want a particular view in a phonegap/cordova app to appear in landscape mode. The various options I've explored so far are:

  • Setting the config.xml. But you'd want this only if you intend the whole app to either be in portrait or landscape
  • Adding manifest.json. (Also taking care that I do not have any orientation settings defined in my config.xml). My plan was to conditionally include the file when I want to set my orientation as landscape.

So for the 2nd option I've written code in my pages such as:

<link rel="manifest" href="manifest.json" ng-if="orientation == 'landscape'">

...and in the controller toggling the value of orientation - with the intent of forcing it on demand.

However the above approach doesn't work.

Any idea on how to make this work?

Community
  • 1
  • 1
deostroll
  • 11,661
  • 21
  • 90
  • 161

1 Answers1

0

I don't know about the angularjs part. But you can try/use Orientationlock plugin to dynamically lock and unlock the Orientation.

From the plugin description

From your JavaScript code call window.plugins.orientationLock.unlock() to unlock orientation, window.plugins.orientationLock.lock("portrait") or window.plugins.orientationLock.lock("landscape") to lock your screen to the specified orientation.

To start your Cordova application pre-locked place setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); or setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); in the onCreate() of your Cordova activity.

Once unlocked, you can track orientation changes with the regular orientationchange event:

window.addEventListener("orientationchange", function() {
   alert(window.orientation);
}); 
Stack User 5674
  • 1,548
  • 1
  • 20
  • 44