Android: detect device slope

It took me several hours to find the best way of detecting device slope on Android.

You Activity should contain the following code:

Note: this worked perfectly on phones in landscape layout. Tablets should be investigated additionally.