Skip to content

SongDanielLi/AndroidNdkSensor

Repository files navigation

NDK Sensor

This is an example of reading Android sensor data via native c++ API, and a simple implementation from JNI.

Pre-requisites

NDK

Example

 // declare your own SensorEventListener
 class MyListener: public NdkSensorEventListener{
 public:
      void onSensorChanged(ASensorEvent *event) override{ // do something }
 }

 NdkSensorManager* manager = NdkSensorManager();
 manager->setListener(new MyListener());
 // register accelerometer with 50 Hz.
 manager->registerSensor({ASENSOR_TYPE_ACCELEROMETER}, 20000);

 // unregister sensors
 manager->unregister();

Reference

NDK Sensor NDK sample

License

License