Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you version code in Android without compiler warnings?

Tags:

android

Google's docs say to use this kind of code to ensure new code is not executed on old platforms:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
}

But when I do that, Eclipse still gives me warnings: "Call requires API level 11 (current min is 7)". What I want is to have my minimum version set to something lower than Honeycomb, have the above conditional statement protect me from running new code on old devices, and not have compiler warnings.

How do I do it?

like image 648
FizzBuzz Avatar asked Aug 16 '12 09:08

FizzBuzz


2 Answers

Add @TargetApi(11) before method.

like image 175
Benito Bertoli Avatar answered Oct 11 '22 12:10

Benito Bertoli


@TargetApi() seems to be the best way to do this, Look up this page

like image 40
Gautam Avatar answered Oct 11 '22 14:10

Gautam