SurfaceView that implements a SensorListener has an onSensorChanged

here is the full code, I tested it out and works great

http://www.anddev.org/2d_tutorial-t3120.html



On Feb 10, 7:00 pm, naxtek <gnax...@gmail.com> wrote:
> Hi everyone,
>
> I'm a software engineering student and I've just bought a T-Mobile G1
> to have a play with :)
>
> I'm wanting to write an app that will untilise the Accelerometer but I
> only seem to be able to read orientation values from it.  Heres my
> code:
>
> package naxtek.app2;
>
> import android.app.Activity;
> import android.hardware.SensorListener;
> import android.hardware.SensorManager;
> import android.os.Bundle;
> import android.view.ViewGroup;
> import android.widget.EditText;
> import android.widget.LinearLayout;
> import android.widget.RelativeLayout;
> import android.widget.TextView;
>
> public class HelloWorld extends Activity implements SensorListener {
>            /** Called when the activity is first created. */
>
>            LinearLayout vg;
>                 TextView tv;
>             private SensorManager sensorManager;
>
>           �...@override
>            public void onCreate(Bundle savedInstanceState) {
>                super.onCreate(savedInstanceState);
>               tv = new TextView(this);
>               vg = new LinearLayout(this);
>
>                vg.addView(tv);
>                setContentView(vg);
>                sensorManager = (SensorManager) getSystemService
> (SENSOR_SERVICE);
>                sensorManager.registerListener
> (this,SensorManager.SENSOR_ACCELEROMETER,
>                                    SensorManager.SENSOR_DELAY_GAME);
>            }
>
>         public void onAccuracyChanged(int sensor, int accuracy) {
>                 // TODO Auto-generated method stub
>
>         }
>
>         public void onSensorChanged(int sensor, float[] values) {
>                 // TODO Auto-generated method stub
>                 tv.setText("1: ".concat(Float.toString(values[0]))
>                                 .concat("\n2: 
> ".concat(Float.toString(values[1])))
>                                 .concat("\n3: 
> ".concat(Float.toString(values[2])))
>                                 .concat("\n4: 
> ".concat(Float.toString(values[3])))
>                                 .concat("\n5: 
> ".concat(Float.toString(values[4])))
>                                 .concat("\n6: 
> ".concat(Float.toString(values[5])))
>
>                 );
>         }
>
> }
>
> The app runs and works, but all the float values in the array are
> orientation based readings.  They are nothing to do with acceleration
> or G-Forces.
>
> Can anyone give me any pointers as to what to do?
--~--~---------~--~----~------------~-------~--~----~
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-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to