Reputation: 3248
I would like to know if an Android phone actually has an Orientation Sensor. I doubt not all android phones screen changes with change in Orientation (like phones with qwerty keypad)
I have gone through the documentation and found a boolean method 'canDetectOrientation ()' here But I found nothing mentioned in the description. Can anybody tell me if this is the method to find out if a device supports orientation changes .
Thanks in advance.
Upvotes: 1
Views: 1690
Reputation: 5203
If we pass Type.All
in getSensorList
function then we will get list of all available sensor.
Then we can traverse a list and fetch Sensor type of all sensor if we found Sensor type Orientation (integer value is 3) then we can conclude that that device has that sensor.
Below is code snippet for the same.
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);
Upvotes: 2
Reputation: 7790
You can take a look at the actual android source code. Just follow the crumbs at http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.1.1_r1/android/view/OrientationEventListener.java#OrientationEventListener.canDetectOrientation%28%29
Upvotes: 1