How to detect screen rotation on Android in Kivy?
<p>I have been searching for a Kivy solution to capture the Android device rotation from one orientation to another.  I have tried both of the window methods below but neither executes the <code>on_rotate</code> or <code>rotate_screen</code> routines when I rotate the device. I see there is an <code>onConfigurationChanged</code> event in java but I can't find the same event handling for Kivy.</p>

<pre><code>    Window.on_rotate(self.on_rotate)
    Window.bind(on_rotate=self.rotate_screen)        
</code></pre>

<p>What I do get in the logcat is the following messages indicating the device has rotated but my app never see these events.</p>

<pre><code>I/InputReader(270): Reconfiguring input devices.  changes=0x00000004
I/InputReader(270): Device reconfigured: id=3, name='ilitek_i2c', surface size is now 1280x800, mode is 1
I/ActivityManager(270): Config changed: {1.0 0mcc0mnc en_US sw800dp w1280dp h752dp xlrg land finger -keyb/v/h -nav/h s.8}
</code></pre>

<p>I think on_rotate only tracks Kivy's internal rotation (this is done in OpenGL and doesn't relate to the Android level rotation).</p>

<p>You can probably use pyjnius to work with the normal Java methods for this, but I don't know the details. A simple solution that may work just as well is to watch <code>Window.size</code> (<code>from kivy.core.window import Window</code>) - this should detect the change from portrait to landscape.</p>

android python rotation kivy onconfigurationchanged