Identify Android version by some method

Asked

Viewed 3,128 times

2

Is there any method to identify the user’s Android version as soon as it enters the application?

It will be useful for the application to run or not animations between screen transitions, if the user has an older version, it will not run, if it has a more updated version, it will execute the animated transition.

1 answer

5

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.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.