Querying hardware capabilities in Xperia

Sony Ericsson Xperia Play is not a rumored device anymore it’s a real device that you can get a hold off from your telco company. The Play device brings the...

Sony Ericsson Xperia Play is not a rumored device anymore it’s a real device that you can get a hold off from your telco company. The Play device brings the experience of PSP to a mobile device which is a win for consumer. Sony Ericsson has come out with a comprehensive details to make developer’s life easier for building games in Xperia Play, it is also available in PDF format.

approval payday loans

One of the key feature of Android is it’s modular design where the hardware layer is abstracted through APIs making it possible for device manufacturers to create variety of device features without the developers need to do anything special to our code. One of the built-in hardware manager provided by Android is SensorManager. This allows the developer to query the hardware capabilities of the device allowing it to tune the application specific to that particular device, in this case Xperia Play device.

Following sample snippets shows how to query Android to get information about a specific sensor

{code type=”java”}
sm = (SensorManager) getSystemService(SENSOR_SERVICE);
setContentView(R.layout.main);
xViewA = (TextView) findViewById(R.id.xbox);
yViewA = (TextView) findViewById(R.id.ybox);
zViewA = (TextView) findViewById(R.id.zbox);
xViewO = (TextView) findViewById(R.id.xboxo);
yViewO = (TextView) findViewById(R.id.yboxo);
zViewO = (TextView) findViewById(R.id.zboxo);
}
public void onSensorChanged(int sensor, float[] values) {
synchronized (this) {
Log.d(tag, “onSensorChanged: ” + sensor + “, x: ” +
values[0] + “, y: ” + values[1] + “, z: ” + values[2]);
if (sensor == SensorManager.SENSOR_ORIENTATION) {
xViewO.setText(“Orientation X: ” + values[0]);
yViewO.setText(“Orientation Y: ” + values[1]);
zViewO.setText(“Orientation Z: ” + values[2]);
}
if (sensor == SensorManager.SENSOR_ACCELEROMETER) {
xViewA.setText(“Accel X: ” + values[0]);
yViewA.setText(“Accel Y: ” + values[1]);
zViewA.setText(“Accel Z: ” + values[2]);
}
}
}
public void onAccuracyChanged(int sensor, int accuracy) {
Log.d(tag,”onAccuracyChanged: ” + sensor + “, accuracy: ” + accuracy);
}
@Override
protected void onResume() {
super.onResume();
// register this class as a listener for the orientation and accelerometer sensors
sm.registerListener(this,
SensorManager.SENSOR_ORIENTATION |SensorManager.SENSOR_ACCELEROMETER,
SensorManager.SENSOR_DELAY_NORMAL);
}
{/code}

About nanik