I think the reason you see only examples using accelerometer values ββis because the gravity sensor was only launched in API 9, and also because most phones could not separate these values ββfrom the accelerometer values ββor not have sensor etc etc ..
Another reason is that in most cases the result tends to be the same, because what the accelerometer sensor gives out is linear acceleration of the device and gravity, but most of the time the phone will stand or even move at a constant speed, so the acceleration of the device will be zero .
From setRotationMatrix Android Docs:
The matrices returned by this function make sense only when the device does not fall freely and it is not close to magnetic north. If the device is accelerated or placed in a strong magnetic field, the returned matrices may be inaccurate.
Now you ask, will gravity data be more reliable? Well, there is nothing like testing, but I believe that it will not make much difference, and it really depends on which application you want. Also, getting simple gravity is not trivial, and it requires filtering, so you can get noisy results.
source share