Sunday, October 2, 2011

[android-developers] Re: Rotation Vector Sensor

So..after more research and using a HTC Sensation with a gyro it turns
out you do need a gyro for this to work!

On Sep 22, 2:31 pm, Kingcrowley <kingcrow...@gmail.com> wrote:
> Trying to use the Rotation Vector Sensor on a Nexus One 2.3.4 (it is
> listed as having it)
>
> When i run this it crashes..when i debug it it seems to have returned
> values but then crashes?? any ideas? thanks!
>
> public class SensorActivity extends Activity implements
> SensorEventListener {
>         private SensorManager mSensorManager;
>         private TextView tv14,tv15,tv16;
>
>         public void onCreate(Bundle savedInstanceState) {
>                 super.onCreate(savedInstanceState);
>                 setContentView(R.layout.main);
>                 mSensorManager = (SensorManager)
> getSystemService(SENSOR_SERVICE);
>
>                 tv14 = (TextView)findViewById(R.id.text14);
>                 tv15 = (TextView)findViewById(R.id.text15);
>                 tv16 = (TextView)findViewById(R.id.text16);
>         }
>
>         @Override
>         public void onAccuracyChanged(Sensor arg0, int arg1) {
>                 // TODO Auto-generated method stub
>
>         }
>
>         @Override
>         public void onSensorChanged(SensorEvent event) {
>
>                 Sensor mySensor = event.sensor;
>
>                 if (mySensor.getType() == Sensor.TYPE_ROTATION_VECTOR)
> {
>                         float rX = event.values[0];
>                         float rY = event.values[1];
>                         float rZ = event.values[2];
>
>                         tv14.setText("RV(x)= " + rX);
>                         tv15.setText("RV(y) = " + rY);
>                         tv16.setText("RV z = " + rZ + "\n");
>                 }
>
>         }
>         protected void onPause(){
>
>                 mSensorManager.unregisterListener(this);
>                 super.onStop();
>         }
>         protected void onStop() {
>                 mSensorManager.unregisterListener(this);
>                 super.onStop();
>         }
>         protected void onResume()
>         {
>                 super.onResume();
>
>                 mSensorManager.registerListener(this,
> mSensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR) ,
> SensorManager.SENSOR_DELAY_GAME);
>
>         }
>
>
>
>
>
>
>
> }

--
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

No comments:

Post a Comment