检测设备方向 [英] Detecting device orientation
问题描述
我需要检测的Android设备方向的变化,而不带传感器的数据手动播放,同时保持活动的方向坚持一些方向
I need to detect android device orientation change without playing manually with sensor data, while keeping activity orientation stick to some orientation
onConfigurationChange
将不作为会坚持我的活动不旋转工作。
onConfigurationChange
will not work as will stick my activity to not rotate.
与传感器数据播放周围以检测取向变化我认为,由于车轮的发明中,作为机器人已经确实有该算法的嵌入式实施,以检测设备取向的变化。而从另一个侧面方向变化的检测并不是一个简单的检查是这样的。
Playing around with sensor data to detect the orientation change I consider that as an invention of wheel, as android already does have embedded implementation of the algorithm to detect device orientation change. And from another side the detection of orientation change is not a simple checks like this.
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() != Sensor.TYPE_ACCELEROMETER || event.values.length < 3) {
return;
}
//getResources().getConfiguration().orientation;
if (event.values[1] < 6.5 && event.values[1] > -6.5) {
if (orientation!=1) {
Log.d("Sensor", "Protrait");
}
orientation=1;
} else {
if (orientation!=0) {
Log.d("Sensor", "Landscape");
}
orientation=0;
}
}
它真的需要像噪音和突发短路抖动/旋转过滤真正的数据处理。
It does really require real data processing like filtration from noise and sudden short shakes/rotations.
那么怎样设备的方向可以用传统服务来检测任何想法? (再一次,我会坚持我的活动,一些方向,使 onConfigurationChange
将无法正常工作)
So any ideas how the device orientation can be detected using legacy services ? (Once again, I'll stick my activity to some orientation so onConfigurationChange
will not work)
推荐答案
有一个监听器定位-事件。
There is a Listener for Orientation-Event.
<一个href="http://stackoverflow.com/questions/7095654/implementing-orientationeventlistener-to-help-camera-issues-without-camerainfo">SO问题提的实现,监听器的。
我希望这会帮助你。
这篇关于检测设备方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!