I am aware how to get the orientation angle between the y-axis of the phone and the magnetic north using the getOrientation method (as described here https://developer.android.com/guide/topics/sensors/sensors_position). However, I would need the orientation between the z-axis of the phone and the magnetic north, so to get the direction of the phone's camera. I have tried writing my own code to calculate this angle from the angle between the y-axis and the magnetic north, but it gives me unreliable data, even if corrected with the gravity sensor data (e.g. when the phone is flipped over).
Is there a way to directly get the angle between the z-axis and the magnetic north?