Android 传感器 TYPE_LINEAR_ACCELERATION 和 TYPE_ROTATION_VECTOR 是如何实现的?
How are Android sensor TYPE_LINEAR_ACCELERATION and TYPE_ROTATION_VECTOR implemented?
我一直在寻找 Android API 用于融合来自不同传感器的原始数据以生成虚拟传感器的算法。
它们是如何实施的?
源代码在某处可用吗?
您必须获取传感器管理器的实例
private SensorManager mSensorManager;
private Sensor mSensor;
...
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
之后您可以像这样访问加速度计数据:
public void onSensorChanged(SensorEvent event){
// In this example, alpha is calculated as t / (t + dT),
// where t is the low-pass filter's time-constant and
// dT is the event delivery rate.
final float alpha = 0.8;
// Isolate the force of gravity with the low-pass filter.
gravity[0] = alpha * gravity[0] + (1 - alpha) * event.values[0];
gravity[1] = alpha * gravity[1] + (1 - alpha) * event.values[1];
gravity[2] = alpha * gravity[2] + (1 - alpha) * event.values[2];
// Remove the gravity contribution with the high-pass filter.
linear_acceleration[0] = event.values[0] - gravity[0];
linear_acceleration[1] = event.values[1] - gravity[1];
linear_acceleration[2] = event.values[2] - gravity[2];
}
有关详细信息,请阅读 developer.android Page
Is the source code available somewhere?
不幸的是,Fused Location Provider API 不是 Android 开源项目的一部分,而是作为 Google Play Services 的一部分实现的,后者是专有 Google 软件及其源代码不公开。事实上,FusedLocationProviderApi.java
接口实现是有意混淆的,例如:
public class zzd implements FusedLocationProviderApi {
public zzd() {
}
public Location getLastLocation(GoogleApiClient var1) {
zzl var2 = LocationServices.zzj(var1);
try {
return var2.getLastLocation();
} catch (Exception var4) {
return null;
}
}
...
How have they been implemented?
由于无法获得源代码,我们只能推测其具体实现方式。
我一直在寻找 Android API 用于融合来自不同传感器的原始数据以生成虚拟传感器的算法。
它们是如何实施的? 源代码在某处可用吗?
您必须获取传感器管理器的实例
private SensorManager mSensorManager;
private Sensor mSensor;
...
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
之后您可以像这样访问加速度计数据:
public void onSensorChanged(SensorEvent event){
// In this example, alpha is calculated as t / (t + dT),
// where t is the low-pass filter's time-constant and
// dT is the event delivery rate.
final float alpha = 0.8;
// Isolate the force of gravity with the low-pass filter.
gravity[0] = alpha * gravity[0] + (1 - alpha) * event.values[0];
gravity[1] = alpha * gravity[1] + (1 - alpha) * event.values[1];
gravity[2] = alpha * gravity[2] + (1 - alpha) * event.values[2];
// Remove the gravity contribution with the high-pass filter.
linear_acceleration[0] = event.values[0] - gravity[0];
linear_acceleration[1] = event.values[1] - gravity[1];
linear_acceleration[2] = event.values[2] - gravity[2];
}
有关详细信息,请阅读 developer.android Page
Is the source code available somewhere?
不幸的是,Fused Location Provider API 不是 Android 开源项目的一部分,而是作为 Google Play Services 的一部分实现的,后者是专有 Google 软件及其源代码不公开。事实上,FusedLocationProviderApi.java
接口实现是有意混淆的,例如:
public class zzd implements FusedLocationProviderApi {
public zzd() {
}
public Location getLastLocation(GoogleApiClient var1) {
zzl var2 = LocationServices.zzj(var1);
try {
return var2.getLastLocation();
} catch (Exception var4) {
return null;
}
}
...
How have they been implemented?
由于无法获得源代码,我们只能推测其具体实现方式。