Yes, you can check by version constants.
In general, for incompatibility handling of some API functions it is common to use the constant Build.VERSION.SDK_INT
, that has the information of which version the device is running.
And along with SDK values, available in the class Build.VERSION_CODES
you can run code conditioned the version the application will run on.
An example would be:
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
ViewPropertyAnimator vpa = view.animate();
// Restante do código usando ViewPropertyAnimator
} else {
Animation an = new AlphaAnimation(0f, 1f);
// Restante do código usando a API View Animation
}
This code will not work for devices with version smaller than SDK 4 (Android 1.6 Donut), these constants were added in this version.