Identify Android version by some method

2

Is there a method to identify the user's Android version as it enters the app?

It will be useful for the application to run animations between screen transitions, if the user has an older version, will not run, if you have a more up-to-date version, perform the animated transition.

    
asked by anonymous 04.10.2014 / 23:27

1 answer

5

Yes, you can check for the version constants.

In general, for handling incompatibility of some API functions it is common to use the constant Build.VERSION.SDK_INT , which has the information of which version the device is running.

And along with the values of the SDKs, available in the class Build.VERSION_CODES you can execute code condition the version in which the application will run.

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 a smaller version than SDK 4 (Android 1.6 Donut), these constants have been added in this release.

    
04.10.2014 / 23:39