How to use the phone's accelerometer?

I’ve been trying to get the acceleromter to work in cocos2d-x c++. I tried to add this function to my scene which a lot of my Google search results said I should:

virtual void didAccelerate(Acceleration *acceleration);

That does however give me an error saying I’m overriding a final function. Then I found a search result saying how I could use the EventDispatcher thing for it.

auto accListener = EventListenerAcceleration::create(CC_CALLBACK_2(MainScene::accelerated, this));
getEventDispatcher()->addEventListenerWithSceneGraphPriority(accListener, this);

In both of these I had called this function earlier in my scene’s init function:

setAccelerometerEnabled(true);

I’m all out of ideas and I need help. On the second “approach” it compiled, but my accelerated function was never called.

Thank you in advance!

I’m using Android so maybe I need to edit something in the AndroidManifest?

Question on Stackoverflow

We have this: http://cocos2d-x.org/docs/programmers-guide/8/index.html#creating-an-accelerometer-event

But I haven’t tested this in quite some time.

The problem was that I didn’t call this:

Device::setAccelerometerEnabled(true);

but I called this:

setAccelerometerEnabled(true);

Otherwise the EventListener is the right way to go.

Thank you very much!