You can get the accelerometer like this in C++:
ASensorManager *sensorManager = ASensorManager_getInstance();
const ASensor *accelSensor = ASensorManager_getDefaultSensor(sensorManager, ASENSOR_TYPE_ACCELEROMETER);
Then create an event queue for the sensors.
ASensorEventQueue *sensorEventQueue = ASensorManager_createEventQueue(sensorManager, looper, LOOPER_ID_USER, NULL, NULL);
If you use the android_native_app_glue "framework" the looper is in the struct android_app that is passed to your android_main.
Then when your main-loop poll (ALooper_pollAll?) returns LOOPER_ID_USER (I guess you can build your own messages by adding +1 +2 etc to LOOPER_ID_USER), handle the sensor-events:
ASensorEvent sensorEvent;
ssize_t sensorResult = ASensorEventQueue_getEvents(sensorEventQueue, &sensorEvent, 1);
while(sensorResult > 0) {
codeToHandleSensorEvent(sensorEvent);
sensorResult = ASensorEventQueue_getEvents(sensorEventQueue, &sensorEvent, 1);
}
And finally handle the ASensorEvent:
switch(sensorEvent.type) {
case ASENSOR_TYPE_ACCELEROMETER:
sensorEvent.acceleration.x;
sensorEvent.acceleration.y;
sensorEvent.acceleration.z;
break;
}
I'm not really an expert at this stuff, but that's how I do it when using android_native_app_glue and run the main-loop from android_main.
EDIT: You also need to enable the sensor I think with ASensorEventQueue_enableSensor, and you can disable it when your app loses focus for example to avoid using it unnecessarily. And there's an ASensorEventQueue_setEventRate for setting how often you want data events from it.
Check <android/sensor.h>, it's the header with the functions and structures and has some comments in it.