Skip to content

Instantly share code, notes, and snippets.

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.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. */
public void onCreate(Bundle savedInstanceState)
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(;
TextView y_field = (TextView) findViewById(;
TextView z_field = (TextView) findViewById(;
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