Skip to content

Instantly share code, notes, and snippets.

@wmbest2
Created January 19, 2010 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wmbest2/281026 to your computer and use it in GitHub Desktop.
Save wmbest2/281026 to your computer and use it in GitHub Desktop.
package com.bestpnd.MagneticFieldMeter;
import android.app.Activity;
import android.os.Bundle;
import android.hardware.*;
import android.widget.TextView;
import java.lang.Float;
public class MagFieldMonitor extends Activity
{
static SensorEventListener sensorEL;
static SensorManager sensorM;
static Sensor sensor;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
sensorM = (SensorManager)this.getSystemService(this.SENSOR_SERVICE);
sensorEL = new SensorEventListener() {
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
public void onSensorChanged(SensorEvent event) {
TextView x_field = (TextView) findViewById(R.id.widget40);
TextView y_field = (TextView) findViewById(R.id.widget41);
TextView z_field = (TextView) findViewById(R.id.widget42);
x_field.setText(Float.toString(event.values[0]));
y_field.setText(Float.toString(event.values[1]));
z_field.setText(Float.toString(event.values[2]));
}
};
sensor = sensorM.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
sensorM.registerListener(sensorEL, sensor, SensorManager.SENSOR_DELAY_NORMAL); // <---- offending line?
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment