Check Android build project target API level at runtime

android, android-build

Solution

I didn't understand your problem completely. But if you want to check which Build Version your app is working on and then act accordingly the you can use the following.

if(Build.VERSION.SDK_INT == 18 ){
    // Do some stuff
}
else if (Build.VERSION.SDK_INT == 19) {
    // Do some stuff
}
else{
    // Do some stuff
}

Problem

I have an application, and it behaves differently when I run it on API 18 or 19. This is not a problem, and I know why does it happen. However, I want to write one code that will deal with both the versions. Is there any way to get in runtime which API my application was built with? Specifically, I would like to get 18 or 19 if I build my application with these APIs. EDIT It seems to be a duplicate question. I thought that the BUILD_VERSION is something else, because, when I compiled both the versions to API 18 and 19, and print the version, I receive 18. It looks like another problem (although I specified API 19, it is compiled according to 18). I found that the problem was in the emulator configurations.

Original source

Related problems