For Android Versions 3.0 and higher, I want to call a certain method.
Is there a way to check if a certain method is available in the running Android Version?
To be more precise, my MinSDK is 7 (Android 2.1), TargetSDK is 8 (Android 2.2) and I need to test
if HoneyComb Android 3.0 or higher is running.
Depending on that, how can I call that HoneyComb method?
The second part of the question arises, because simply calling that HoneyComb method, will not compile, as I am building against 2.2.
Step #1: Set your build target to the highest API level you wish to call directly and therefore compile against. Your build target (e.g.,
compileSdkVersionin Android Studio, Project > Properties > Android in Eclipse) is not related to yourandroid:targetSdkVersion.Step #2: As the other answers have indicated, you can then conditionally call methods within a guard block:
You need to change your build target to be API Level 11 or higher if you wish to directly call API Level 11 or higher methods.