Orientation sensor problem.

by Cardy » Wed, 02 Jun 2010 07:14:45 GMT


Sponsored Links
 Hi all!

I've been trying to get a simple test app working to show me the
orientation of the phone. The code I've used is below:

public class Main extends Activity implements SensorEventListener {

        SensorEventListener listener;
        TextView mainText;
        SensorManager sensorMan;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        mainText = (TextView)this.findViewById(R.id.mainString);

        sensorMan =
(SensorManager)this.getSystemService(Context.SENSOR_SERVICE);
        sensorMan.registerListener(
           this,
           sensorMan.getDefaultSensor(
              SensorManager.SENSOR_ORIENTATION),
           SensorManager.SENSOR_DELAY_NORMAL);
    }

        @Override
        public void onAccuracyChanged(Sensor sensor, int accuracy) {
                // TODO Auto-generated method stub

        }

        @Override
        public void onSensorChanged(SensorEvent event) {

                float[] values = event.values;
            mainText.setText(
                                "AngleX: "+ values[0]  +
                                "AngleY: "+ values[1] +
                                "AngleZ: "+ values[2] );
        }
}

So from what I've seen everywhere, the angles should range somewhere
between -360 to 360 or -180 to 180. Something like that anyway. But
what I'm receiving when testing on my T-Mobile G2 is completely
different:

AngleX: -10 to 10
AngleY: -10 to 10
AngleZ: -11 to 11

Initially I assumed this was radians but it's outside of -PI to PI
(i.e. it'd be > 360 degrees which is contrary to all the blog posts
I've seen.

If anyone else has heard of this or seen this problem I'd love to know
what you did!

Any information or ideas are welcome!

Thanks a lot!

Andy.

--



Orientation sensor problem.

by ThomasWrobel » Wed, 16 Jun 2010 04:42:29 GMT


 Did you ever get to the bottom of this?
I think I'm having a similar problem.




--


Sponsored Links


Other Threads

1. Question about using LayoutInflater

I have a question about using LayoutInflater.

I have a class which inherits from 'View'.

It calls

LayoutInflater inflater =
(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        
                if (inflater != null) {
                        inflater.inflate(R.layout.mycontent, null);
                }

inflate returns with no exception.

But then, when I do this:
mRowLayout = (RelativeLayout)findViewById(R.id.row_layout);

I get a null pointer for mRowLayout.

Can you please tell me why? Or how to fix my problem?

<?xml version="1.0" encoding="utf-8"?>
<view class="android.widget.RelativeLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/carousel_film"
        android:layout_width="fill_parent" android:layout_height="fill_parent">
        <RelativeLayout
                        android:id="@+id/row_layout"
                        android:layout_width="fill_parent">
                        
                        <ImageView
                                android:id="@+id/left"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:src="@drawable/left"
                                />
        </RelativeLayout>
</view>

--~--~---------~--~----~------------~-------~--~----~

2. debugging java and c/c++

I can debug the Android Java code using eclipse and using the Remote
Java Application debug
configuration. This does not step into C/C++ code however as expected.
I understand I have to attach the gdbserver to do this. Can someone
provide a step by step tutorial on how to debug the native code of
Android?

Is there a eclipse plugin that makes this easier?

--~--~---------~--~----~------------~-------~--~----~

3. Market Place refund is automatically uninstalling apps.

4. Market Place refund is automatically uninstalling apps.

5. OnTouchListener

6. How can I create a custom composite widget in android

7. Nice Settings Management?