As you may know since a couple of month you can write native Android apps using RubyMotion.

Last weeks I used it to build an Android app and had the need to lock the screen is portrait mode.

Using the classical Java / XML toolchain to build an app, you have to add an attribute to your activity in the AndroidManifest.xml file:

<activity android:name="MainActivity" android:label="Awesome App" android:screenOrientation="portrait" >

When using RubyMotion you don’t edit this manifest file by hand, all configuration stuff are done through the Rakefile. Translating this in RubyMotion is simple:

Motion::Project::App.setup do |app|
  # …
  app.manifest.child('application').child('activity').update('android:screenOrientation' => 'portrait')
end

This is the only thing needed to lock the application in portrait mode. Of course you can lock in landscape mode.

Note it’s not always a good thing to lock screen orientation in your application. Don’t do this to workaround bugs or difficulties. Use it only if your application isn’t meant to be used in both orientations.

Have comments or want to discuss this topic?

Send an email to ~bounga/public-inbox@lists.sr.ht