Rotation Vector Sensor Android – Gyroscope

After messing around with sensors for a while and tried to see what TYPE_ROTATION_VECTOR actually returned as values. The docs seemed pretty sparse to me!

But whenever I tried to run a simple program to display the sensor output the activity crashed….due to a null pointer exception. Read a few posts and none was very clear….some mentioned that a gyroscope was needed…

Found this post which implies the device needs a gyroscope to implement a Rotation Vector Sensor.

Not 100% but as much information as I can find online!

Displaying a list of Sensors available on an Android device (Gingerbread) 2.3.3 used

Code below displays all available sensors (hardware and virtual)

import java.util.List;
import android.app.Activity;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.widget.TextView;

public class SensorListActivity extends Activity implements SensorEventListener {
	private SensorManager mSensorManager;
	private TextView mTextView;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
		mTextView = (TextView) findViewById(R.id.text_view);

		List<Sensor> mList
        = mSensorManager.getSensorList(Sensor.TYPE_ALL);
		for (int i = 1; i < mList.size(); i++) {
			mTextView.append("\n" + mList.get(i).getName());
			}
	}

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

	}

	@Override
	public void onSensorChanged(SensorEvent event) {
		// TODO Auto-generated method stub 

	}
	protected void onPause(){
		super.onStop();
	}
	protected void onStop() {
		super.onStop();
	}
	protected void onResume()
	{
		super.onResume();
	}

}

main.xml (just a textview to show the list of sensors)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView
	android:id="@+id/text_view"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 

    />
</LinearLayout>
Sensors list displayed on Nexus One
Sensors list displayed on Nexus One