Accessing sensors at Android NDK
Many Android devices have built-in sensors to detect and measure motion, orientation, and other environmental conditions. It is possible to access sensors in Android NDK. This recipe will discuss how to do it in detail.
Getting ready
The example provided in this recipe is based on the sample code in the previous two recipes. Readers are recommended to read them first:
Managing native windows at Android NDK
Detecting and handling input events at Android NDK
How to do it…
The following steps develop the sample Android application, which demonstrates how to access sensors from Android NDK:
Create an Android application named
nativesensors
. Set the package name ascookbook.chapter5.nativesensors
. Please refer to the Loading native libraries and registering native methods recipe of Chapter 2, Java Native Interface, if you want more detailed instructions.Right-click on the
nativesensors
project, select Android Tools | Add Native Support.Update
AndroidManifest.xml
. Please...