Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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