I'm using onSensorChanged(). What should I specify in <uses-feature>?
I've checked the doc here: http://developer.android.com/guide/topics/manifest/uses-feature-element.html
and found 2 most relevant features:
1) android.hardware.sensor.accelerometer
2) android.hardware.sensor.compass
Which one do I need to specify in my manifest? Or both?
Yes, I'm sure I'm using the accelerometer. But the Accelerometer and Magnetic Field values are also used to calculate "Direction" (which also means I'm using android.hardware.sensor.compass ??)
Here's my code:
@Override
public void onSensorChanged(SensorEvent event) {
int type = event.sensor.getType();
switch (type) {
case Sensor.TYPE_MAGNETIC_FIELD:
mags = event.values.clone();
break;
//I'm using Accelerometer here
case Sensor.TYPE_ACCELEROMETER:
accels = event.values.clone();
开发者_JAVA百科 break;
}
SensorManager.getRotationMatrix(rotationMat, I, accels, mags);
SensorManager.getOrientation(rotationMat, calculatedOrients);
//I also get direction here, So do I need to specify android.hardware.sensor.compass in <uses-feature> ?
azimuth = (float) Math.toDegrees(calculatedOrients[0]);
pitch = (float) Math.toDegrees(calculatedOrients[1]);
roll = -(float) Math.toDegrees(calculatedOrients[2]);
}
Thank you in advance!
I think you answer it yourself and should use both.
Make sure you can set the required to false and have your application write a notice to the user. Else you might not be able to distribute it to older clients through the Android Market.
<uses-feature android:name="android.hardware.sensor.accelerometer" android:required="true" />
<uses-feature android:name="android.hardware.sensor.compass" android:required="true" />
精彩评论