From Game developer tip 4: Displaying game keys and buttons accurately — Developer World
10th August 2011.
22:04
[...] Read our second game developer tip on querying hardware capabilities.>>> [...]
0
0
This is the second in a series of tips that supplement the Xperia™ game developer recommendations. This tip expands on Input recommendation IN5 in the list of game developer recommendations: A game should query the possible hardware capabilities of the platform to check if they exist on the current device. You can also download a PDF of this article.
Recommendation
A game should query the possible hardware capabilities of the platform to check if they exist on the current device.
Background
Android™ runs on platforms of varied capabilities and developers often assume that they have access to certain features, which might not be supported by all Android™ devices. This makes it essential for developers to query for hardware before actually trying to access a resource. Thus, it will also help them to avoid unnecessary crashes and make their applications compatible to majority of devices.
Many devices have special hardware capabilities, such as the touch pad in the Xperia™ Play or the pressure sensor in the Xperia™ active, which should be taken advantage of when developing applications. It’s important to enumerate the capabilities of the device at run time and not assume that certain capabilities exist.
Special considerations
Graphics-based applications should query, screen size, resolution, OpenGL capability, graphics processor, etc. Other sensor-based queries can be done using SensorManager.
Examples
Some of the hardware-oriented features available with the Android platform include:
A sample code snippet for the sensor is below:
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);
}
A code example for querying the version of OpenGL that is supported by a phone is below:
public int getGLVersion()
{
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
ConfigurationInfo info = am.getDeviceConfigurationInfo();
return info.reqGlEsVersion;
}
The types of sensors that can be queried through SensorManager are described in the Android Developer Reference guide.
About the Game Developer Tips
The Xperia™ game developer recommendations offers guidance in developing games for Xperia™ devices such as Xperia™ PLAY. The tips in this series provide additional information about some of the significant recommendations in that document. Each tip provides the following information:
More information
From Game developer tip 4: Displaying game keys and buttons accurately — Developer World
10th August 2011.
22:04
[...] Read our second game developer tip on querying hardware capabilities.>>> [...]
0
0
From Game developer tip 3: Installing large APK files to the SD card — Developer World
29th August 2011.
20:03
[...] Read our second game developer tip on querying hardware capabilities.>>> [...]
0
0
Sort by