gpt4 book ai didi

安卓 : Orientation : Find out if a device supports orientations change

转载 作者:行者123 更新时间:2023-11-29 18:05:16 24 4
gpt4 key购买 nike

我想知道 Android 手机是否真的有方向传感器。我怀疑并不是所有的安卓手机屏幕都会随着方向的改变而改变(比如带有 qwerty 键盘的手机)

我浏览了文档并找到了一个 bool 方法“canDetectOrientation ()” here但是我在描述中没有发现任何提及。谁能告诉我这是不是查明设备是否支持方向更改的方法。

提前致谢。

最佳答案

如果我们在 getSensorList 函数中传递 Type.All,那么我们将获得所有可用传感器的列表。

然后我们可以遍历一个列表并获取所有传感器的传感器类型,如果我们找到传感器类型方向(整数值为 3),那么我们可以断定该设备具有该传感器。

下面是相同的代码 fragment 。

boolean OrientationSensorFound=false;
SensorManager mSensorManager;
Sensor mSensor;

mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
List<Sensor> mSensorList = mSensorManager.getSensorList(Sensor.TYPE_ALL );

for(int i=0;i<mSensorList.size();i++){
// 3 is value for Orientation sensor
if(Sensor.TYPE_ORIENTATION==mSensorList.get(i).getType()){
OrientationSensorFound=true;
break;
}
}
Log.i("Sensor Found", "Orientation found : "+OrientationSensorFound);

关于安卓 : Orientation : Find out if a device supports orientations change,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13716698/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com