[android-developers] Re: Compass Reading - proper implementation.



On Monday, March 17, 2014 4:40:21 PM UTC-7, Nathan wrote:
Last time I worked on a compass reading (which was years ago), I did something like this.

A:
http://www.javacodegeeks.com/2013/09/android-compass-code-example.html

Of course, this example has a locked portrait orientation.

So, I call something like this to get it in sync.
http://developer.android.com/reference/android/view/Display.html#getRotation()

Now, I realize that some of the calls in example A are deprecated. Many devices with which I am familiar, though, it actually does work.

That's why, if I were to do a new implementation today, I might consider something like implementation B.  

B:
http://sunil-android.blogspot.com/2013/02/create-our-android-compass.html

I have no good way of testing either method on all of today's gazillion Android devices, so I am going to have to use a best practice, and try to blame the user's device when they don't work.

So my questions are:
1. Does implementation B already take into account landscape/portrait orientation of the device, or should I continue to use Display.getRotation?
2. Are there known devices for which A fails and B works or vice versa?
3. Are there devices with usable sensors for which neither A or B works?
4. Are there any known drawbacks of implementation B?

Nathan


To follow up with my question from a several months ago.

I can confirm that the deprectated Orientation sensor method (method A above) is broken in some devices. Not just wrong values - no values apparently.

Two users at once told me they were getting no compass readings. When two users at once do that, I can expect the problem will soon be widespread.
Xperia M2, and Samsung S4 mini.

A log file from one showed this:
07-08 21:39:35.103 E/SensorManager(15370): sensor or listener is null

I had both implementations in the code, but never really activated method B because of no real testing.

I sent custom apk to one of the users, and method B worked. Both method A and method B work on the Galaxy note 3, which I have.

Method B is much more jittery, and I expect that is the case in all devices. Don't know how to resolve that yet, and haven't seen gimbal lock yet to comment. 

Nathan


--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups "Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.