Home > database >  I cannot lock Cordova screen mode using screen orientation plugin
I cannot lock Cordova screen mode using screen orientation plugin

Time:12-24

I can't lock my screen mode to portrait using the screen orientation plugin in Cordova android Every time I tried it allowed me to rotate to landscape mode

I tried to use this code but it doesnt work

            function onDeviceReady() {
                screen.orientation.lock('portrait-primary')
            }

            document.addEventListener('deviceready', function() {
                onDeviceReady()
            })

I expect it to lock the mode to portrait mode but it doesnt work

CodePudding user response:

Any reason why you are using a plugin for this? You can simply set

 <preference name="Orientation" value="portrait" />

CodePudding user response:

In our app we do it like this:

  window.screen.orientation.lock('portrait-primary');

So I think your problem is that you are not calling it on the window. screen is a property in window, you cannot call on it directly, I think.

  • Related