Similar to GPS Status application in android I want to get the "absolute strength of the magnetic field" and "theoretical strength". I am able to get the theoretical strength using Geom开发者_如何转开发agneticField
getFieldStrength()
method .
But I am not sure how to get the "absolute strength of the magnetic field" from sensors.
Please help.
Thanks.
If you are looking for an absolute value of the magnetic field strength, you could simply calculate it as follows:
private final SensorEventListener mySensorListener = new SensorEventListner() {
public void onSensorChange(SensorEvent event) {
sensorRead = event.value;
int sensorType = event.sensor.getType();
if(sensorType = Sensor.TYPE_MAGNETIC_FIELD) {
mag = sensorRead;
magAbsVal = Math.sqrt(mag[0]*mag[0] + mag[1]*mag[1] + mag[2]*mag[2]);
}
}
}
This will give you the absolute uT value read from the magnetometer. If you are looking for a percentage value, you can use percentMag = largestMag/magAbsVal
.
Hope it helps.
精彩评论