Created
January 19, 2010 15:58
-
-
Save wmbest2/281026 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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