It is already included in the sample android project of SDL2. In SDLActivity.java the onSensorChanged method registers all tilt movements:
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
SDLActivity.onNativeAccel(event.values[0] / SensorManager.GRAVITY_EARTH,
event.values[1] / SensorManager.GRAVITY_EARTH,
event.values[2] / SensorManager.GRAVITY_EARTH);
}
}
Then these values can then be read in your C++ code, by calling the function Android_JNI_GetAccelerometerValues(float values[3]) in sdl_android.c.
So for example your code could look like:
#include "../SDL/src/core/android/SDL_android.h"
float accelValues[3];
Android_JNI_GetAccelerometerValues(accelValues);
after which accelValues will contain the accelerometer values you can use for controlling your game.