Software Archive
Read-only legacy content
17061 Discussions

How can I set the orientation landscape

Augusto_Cesareo_R_
545 Views

Hi

I have to show a barcode (code 128) to my users, it can not be qr, but this code does not fit on the screen, then when clicking on a link the screen should have a horizontal orientation, this using jQuery or Cordova, How can I do this?

Best Regards

0 Kudos
5 Replies
Augusto_Cesareo_R_
545 Views

I found this

https://www.npmjs.com/package/cordova-plugin-screen-orientation

https://www.w3.org/TR/screen-orientation/

What script should I have loaded? cordova.js?

Also mentions "The Screen Orientation API", how can I load this api?

0 Kudos
Augusto_Cesareo_R_
545 Views

Including the following

    <script src="cordova.js" id="xdkJScordova_"></script>

    <script src="js/app.js"></script>           <!-- for your event code, see README and file comments for details -->
    <script src="js/init-app.js"></script>      <!-- for your init code, see README and file comments for details -->
    <script src="xdk/init-dev.js"></script>     <!-- normalizes device and document ready events, see file for details -->
        <script type="text/javascript" charset="utf-8" src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
 

I got it the following errer

Uncaught TypeError: undefined is not a function principal.js:280

I think I should include the Orientation Screen API, but how can I do it?

0 Kudos
Augusto_Cesareo_R_
545 Views

a

 

 

 

0 Kudos
Augusto_Cesareo_R_
545 Views

I successfully installed the plugin but I still have the same error

Uncaught TypeError: undefined is not a function principal.js:280

Other new errors

Uncaught module cordova-plugin-screen-orientation.screenorientation.android already defined 
Uncaught module cordova-plugin-screen-orientation.screenorientation already defined 

I am using

            screen.lockOrientation('landscape');

Then what am i doing wrong?

0 Kudos
PaulF_IntelCorp
Employee
545 Views

Are you doing this testing in the Simulate tab, in App Preview (via Test tab) or on a real device using a built app? I think the screen orientation feature will do nothing in the Simulate tab. I believe it will work in App Preview.

This error message "Uncaught TypeError: undefined is not a function principal.js:280" indicates a problem in your code or in some library you've included as part of your code, it has nothing to do with Cordova or the XDK.

These error messages:

Uncaught module cordova-plugin-screen-orientation.screenorientation.android already defined 
Uncaught module cordova-plugin-screen-orientation.screenorientation already defined 

look like a typical message generated by the Simulate tab, which can be safely ignored. But if you are doing this in the Simulate tab you're not likely to see the orientation feature work. Try it on a real device.

BTW -- the jQuery folks have advised against using jQuery 3 in a Cordova app, it apparently does not work well with some device webviews. I recommend you use jQuery 2.

0 Kudos
Reply