<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Orientation Sensor Tips in Android</title>
	<atom:link href="http://www.workingfromhere.com/blog/2009/03/30/orientation-sensor-tips-in-android/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.workingfromhere.com/blog/2009/03/30/orientation-sensor-tips-in-android/</link>
	<description>working from here, there, and everywhere.</description>
	<lastBuildDate>Fri, 16 Dec 2011 11:10:52 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
	<item>
		<title>By: G.</title>
		<link>http://www.workingfromhere.com/blog/2009/03/30/orientation-sensor-tips-in-android/comment-page-1/#comment-71</link>
		<dc:creator>G.</dc:creator>
		<pubDate>Fri, 16 Dec 2011 11:10:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.workingfromhere.com/blog/?p=21#comment-71</guid>
		<description>Hi, I have a little problem with it.
I use accelerometer and magnetic field like you showed, but when my phone lie on the table the values are changing very fast like crazy. When it&#039;s should show 10, it&#039;s shows values between 6 and 11. 
So this is my questions: Why is that? How I can fix it? I need that to be very accurate.

And I also want use calibrate - sometimes you can see on other apps a warning that your device have to be calibrate and you have to wave your phone in a figure 8 pattern to reset magnetometr in your device.

i checked it in onAccuracyChanged, i checke the accuracy variable, but I don&#039;t sure that it&#039;s enought. Is it?

I hope you can help me, 
Sorry for mistakes if any there, probably there are. ;)

Greetings from Poland for all of you:)</description>
		<content:encoded><![CDATA[<p>Hi, I have a little problem with it.<br />
I use accelerometer and magnetic field like you showed, but when my phone lie on the table the values are changing very fast like crazy. When it&#8217;s should show 10, it&#8217;s shows values between 6 and 11.<br />
So this is my questions: Why is that? How I can fix it? I need that to be very accurate.</p>
<p>And I also want use calibrate &#8211; sometimes you can see on other apps a warning that your device have to be calibrate and you have to wave your phone in a figure 8 pattern to reset magnetometr in your device.</p>
<p>i checked it in onAccuracyChanged, i checke the accuracy variable, but I don&#8217;t sure that it&#8217;s enought. Is it?</p>
<p>I hope you can help me,<br />
Sorry for mistakes if any there, probably there are. <img src='http://www.workingfromhere.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Greetings from Poland for all of you:)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lawrence D’Oliveiro</title>
		<link>http://www.workingfromhere.com/blog/2009/03/30/orientation-sensor-tips-in-android/comment-page-1/#comment-69</link>
		<dc:creator>Lawrence D’Oliveiro</dc:creator>
		<pubDate>Sat, 20 Aug 2011 11:34:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.workingfromhere.com/blog/?p=21#comment-69</guid>
		<description>I have done another sample app that uses OpenGL to display a compass arrow that takes into account all three angle readings. The code is here:

https://github.com/ldo/3D-Compass</description>
		<content:encoded><![CDATA[<p>I have done another sample app that uses OpenGL to display a compass arrow that takes into account all three angle readings. The code is here:</p>
<p><a href="https://github.com/ldo/3D-Compass" rel="nofollow">https://github.com/ldo/3D-Compass</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pranav</title>
		<link>http://www.workingfromhere.com/blog/2009/03/30/orientation-sensor-tips-in-android/comment-page-1/#comment-68</link>
		<dc:creator>Pranav</dc:creator>
		<pubDate>Tue, 19 Jul 2011 11:58:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.workingfromhere.com/blog/?p=21#comment-68</guid>
		<description>Bow to thee!! thanks a lot... I have ruined enough grey cells on this... you saved some from getting wasted!</description>
		<content:encoded><![CDATA[<p>Bow to thee!! thanks a lot&#8230; I have ruined enough grey cells on this&#8230; you saved some from getting wasted!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: iamZoltanVaradi</title>
		<link>http://www.workingfromhere.com/blog/2009/03/30/orientation-sensor-tips-in-android/comment-page-1/#comment-67</link>
		<dc:creator>iamZoltanVaradi</dc:creator>
		<pubDate>Fri, 24 Jun 2011 19:47:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.workingfromhere.com/blog/?p=21#comment-67</guid>
		<description>Thanks for the code it helped me very much!

However if you only use value[2] to determine the orientation, you will never know if the phone is straight or straight,but upside down. for that, you&#039;ll ned value[1] too. if it&#039;s positive, then it&#039;s upside down, if it&#039;s negative, then it&#039;s held straight. hope it helps.

Zoli</description>
		<content:encoded><![CDATA[<p>Thanks for the code it helped me very much!</p>
<p>However if you only use value[2] to determine the orientation, you will never know if the phone is straight or straight,but upside down. for that, you&#8217;ll ned value[1] too. if it&#8217;s positive, then it&#8217;s upside down, if it&#8217;s negative, then it&#8217;s held straight. hope it helps.</p>
<p>Zoli</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shell</title>
		<link>http://www.workingfromhere.com/blog/2009/03/30/orientation-sensor-tips-in-android/comment-page-1/#comment-41</link>
		<dc:creator>Shell</dc:creator>
		<pubDate>Sun, 20 Mar 2011 03:51:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.workingfromhere.com/blog/?p=21#comment-41</guid>
		<description>the m in mGravity and mGeo... implies that they&#039;re module (global) level variables declared at the top of the class. 

they&#039;re likely just float arrays...

private float[] mGravity;
private float[] mGeomagnetic;</description>
		<content:encoded><![CDATA[<p>the m in mGravity and mGeo&#8230; implies that they&#8217;re module (global) level variables declared at the top of the class. </p>
<p>they&#8217;re likely just float arrays&#8230;</p>
<p>private float[] mGravity;<br />
private float[] mGeomagnetic;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: em</title>
		<link>http://www.workingfromhere.com/blog/2009/03/30/orientation-sensor-tips-in-android/comment-page-1/#comment-39</link>
		<dc:creator>em</dc:creator>
		<pubDate>Tue, 08 Feb 2011 18:36:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.workingfromhere.com/blog/?p=21#comment-39</guid>
		<description>I have a question about the mGravity and mGeomagnetic variables. I realized that they&#039;re of type float[]. But i can&#039;t see where you declared them. I&#039;m just curious of what the size should be when you initialize them.</description>
		<content:encoded><![CDATA[<p>I have a question about the mGravity and mGeomagnetic variables. I realized that they&#8217;re of type float[]. But i can&#8217;t see where you declared them. I&#8217;m just curious of what the size should be when you initialize them.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tenaicous</title>
		<link>http://www.workingfromhere.com/blog/2009/03/30/orientation-sensor-tips-in-android/comment-page-1/#comment-38</link>
		<dc:creator>tenaicous</dc:creator>
		<pubDate>Wed, 01 Dec 2010 08:49:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.workingfromhere.com/blog/?p=21#comment-38</guid>
		<description>What versions of Android does this apply to?</description>
		<content:encoded><![CDATA[<p>What versions of Android does this apply to?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ridcully</title>
		<link>http://www.workingfromhere.com/blog/2009/03/30/orientation-sensor-tips-in-android/comment-page-1/#comment-36</link>
		<dc:creator>Ridcully</dc:creator>
		<pubDate>Fri, 08 Oct 2010 12:04:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.workingfromhere.com/blog/?p=21#comment-36</guid>
		<description>Thank you for info, that pitch only goes up to 90 degrees. This confused me immensly.

As to your latest post: The event/listener pattern still works as described by you, but getting the orientation values got quite complicated:

First of all, you&#039;ve got to register the listener for ACCELEROMETER and MAGNETOMETER:

&lt;code&gt;
        Sensor accelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
        Sensor magnetometer = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
        if (accelerometer != null &amp;&amp; magnetometer != null) {
        	mSensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_UI);
        	mSensorManager.registerListener(this, magnetometer, SensorManager.SENSOR_DELAY_UI);
        } else {
        	Log.e(TAG, &quot;no accelerometer!&quot;);
        }

&lt;/code&gt; 

Then in the onSensorChanged method you get events for both sensors. Using them you can get the orientation values like so:

&lt;code&gt;
public void onSensorChanged(SensorEvent event) {
		if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
			mGravity = event.values;
		}
		if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
			mGeomagnetic = event.values;
		}
		if (mGravity != null &amp;&amp; mGeomagnetic != null) {
			float R[] = new float[9];
			float I[] = new float[9];
			boolean success = SensorManager.getRotationMatrix(R, I, mGravity, mGeomagnetic);
			if (success) {
				float orientation[] = new float[3];
				SensorManager.getOrientation(R, orientation);
				// at this point, orientation contains the azimut, pitch and roll values.
			}
		}
		...
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Thank you for info, that pitch only goes up to 90 degrees. This confused me immensly.</p>
<p>As to your latest post: The event/listener pattern still works as described by you, but getting the orientation values got quite complicated:</p>
<p>First of all, you&#8217;ve got to register the listener for ACCELEROMETER and MAGNETOMETER:</p>
<p><code><br />
        Sensor accelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);<br />
        Sensor magnetometer = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);<br />
        if (accelerometer != null &amp;&amp; magnetometer != null) {<br />
        	mSensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_UI);<br />
        	mSensorManager.registerListener(this, magnetometer, SensorManager.SENSOR_DELAY_UI);<br />
        } else {<br />
        	Log.e(TAG, "no accelerometer!");<br />
        }</p>
<p></code> </p>
<p>Then in the onSensorChanged method you get events for both sensors. Using them you can get the orientation values like so:</p>
<p><code><br />
public void onSensorChanged(SensorEvent event) {<br />
		if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {<br />
			mGravity = event.values;<br />
		}<br />
		if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {<br />
			mGeomagnetic = event.values;<br />
		}<br />
		if (mGravity != null &amp;&amp; mGeomagnetic != null) {<br />
			float R[] = new float[9];<br />
			float I[] = new float[9];<br />
			boolean success = SensorManager.getRotationMatrix(R, I, mGravity, mGeomagnetic);<br />
			if (success) {<br />
				float orientation[] = new float[3];<br />
				SensorManager.getOrientation(R, orientation);<br />
				// at this point, orientation contains the azimut, pitch and roll values.<br />
			}<br />
		}<br />
		...<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cephus</title>
		<link>http://www.workingfromhere.com/blog/2009/03/30/orientation-sensor-tips-in-android/comment-page-1/#comment-14</link>
		<dc:creator>cephus</dc:creator>
		<pubDate>Wed, 30 Jun 2010 16:17:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.workingfromhere.com/blog/?p=21#comment-14</guid>
		<description>You are both correct.  Good catch on my mix-up there.  I wanted roll (values[2]) but I inappropriately called it pitch in this post.  My bad.

However, I haven&#039;t worked in the SensorManager lately and this being a year old post I know some of this has changed, multiple times in fact. I should do an update post.

The docs say SensorManager.SENSOR_ORIENTATION is deprecated now and point to Sensor.TYPE_ORIENTATION, which also says it&#039;s deprecated and points to SensorManager.getOrientation().  However that&#039;s an active method of looking up orientation and not applicable for most people&#039;s usage where the previous event/listener pattern worked great.  Oh well, like I said, I need to research it up again and make an update post.

Thanks for calling me out my mixups though.</description>
		<content:encoded><![CDATA[<p>You are both correct.  Good catch on my mix-up there.  I wanted roll (values[2]) but I inappropriately called it pitch in this post.  My bad.</p>
<p>However, I haven&#8217;t worked in the SensorManager lately and this being a year old post I know some of this has changed, multiple times in fact. I should do an update post.</p>
<p>The docs say SensorManager.SENSOR_ORIENTATION is deprecated now and point to Sensor.TYPE_ORIENTATION, which also says it&#8217;s deprecated and points to SensorManager.getOrientation().  However that&#8217;s an active method of looking up orientation and not applicable for most people&#8217;s usage where the previous event/listener pattern worked great.  Oh well, like I said, I need to research it up again and make an update post.</p>
<p>Thanks for calling me out my mixups though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jhavatar</title>
		<link>http://www.workingfromhere.com/blog/2009/03/30/orientation-sensor-tips-in-android/comment-page-1/#comment-13</link>
		<dc:creator>jhavatar</dc:creator>
		<pubDate>Wed, 30 Jun 2010 12:41:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.workingfromhere.com/blog/?p=21#comment-13</guid>
		<description>I concur with Abhinav.

If you want pitch, use &quot;values[1]&quot;. Not &quot;values[2]&quot;.</description>
		<content:encoded><![CDATA[<p>I concur with Abhinav.</p>
<p>If you want pitch, use &#8220;values[1]&#8220;. Not &#8220;values[2]&#8220;.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

