import android.annotation.TargetApi;
and then use annotations:
@TargetApi(11) public void methodUsesAPI11() { ...
Using this trick does a very simple thing: it allows you to compile some code that contains API level 11 calls (classes, methods, etc.) and still sets android:minSdkVersion="8" in the manifest. Nothing more, nothing more.
The rest is up to you. You must check the platform version before calling methodUsesAPI11() or handle exceptions to prevent the application from crashing and perform other actions on older platforms.
source share