Android | Robotium: Get Android Version and Device Details Programmatically

robotium

While working with Android we might face some situations where we have to write device specific code. e.g Some code goes if running on Emulator and Some other code goes if running on Real device.

This is very much useful while working with Test automation framework : Robotium

While developing test scripts to specify some code which is intended to be executed in Emulator or Real device specifically, or to reflect the details in test reports etc these functions are useful.

Procedure to get Android Version of the device along with Device type(Emulator/Real Device)

 Check if device is Emulator or Real device
Boolean deviceType = “google_sdk”.equals(android.os.Build.PRODUCT);
So our stuffs may go like this:

if(deviceType)
{
//Do this that intended for Emulator
}
else
{
//Do this that intended for Real Device
}
 
android.os.Build.VERSION.RELEASE :  Returns Android Version number as a string. e.g 4.1.1
android.os.Build.VERSION.SDK_INT:   Returns Android SDK version number as a string e.g 16
“google_sdk”.equals(android.os.Build.PRODUCT): returns Boolean value as true if device is Emulator and vice-versa
android.os.Build.MANUFACTURER: returns a String containing the Manufacturer name.
android.os.Build.MODEL:  Returns the model number of the device as String.