How to lock ubuntu device orientation in portrait or landscape from user input?

Solution 1:

Unfortunately there's no way yet to set a certain orientation programatically. You can however lock the orientation for your app on a certain one (portrait or landscape) in your app's desktop file. See the following link: https://wiki.ubuntu.com/Unity8/FullShellRotation. The feature has been released some time ago, and perhaps you already use that.