Thanks.
I created a small test app using the code posted, replacing the Log statement with a write to a label.
If I hold my phone vertically and swivel around in my chair, I sort of get accurate numbers a few degrees around North, but nothing much as I swivel through the other 355 degrees. (I'm testing this indoors).
When I hold my phone horizontally, I basically get nothing. (I've tested on several phones, the main one being an LG G3).
I see similar results posted a few posts after the post cited.
On StackOverflow there are many posts essentially using the same two sensors you use. But, I also found one or two posts that use the Geomagnetic_Rotation_Vector sensor. I will try that and see what I get. If I have any success, I will post source code and a small demo app.
It's funny. I downloaded this one free app, Compass (No Ads) by Antoine Vianey, from Google Play. Out of quite a few free compass apps I have downloaded this is the only one that gives accurate numbers when I hold my phone vertically, horizontally, or at any orientation.
I wonder how he did it?
Barry.