Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove "Call requires API level" error?

I get this error in Eclipse: Call requires API level 14 (current min is 8): android.app.ActionBar#setHomeButtonEnabled

This is code:

if(android.os.Build.VERSION.SDK_INT>=14) {     getActionBar().setHomeButtonEnabled(false); } 

In Manifest:

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="14" /> 

How to remove this error?

like image 793
BArtWell Avatar asked Sep 27 '12 23:09

BArtWell


People also ask

How do I change the API level on my phone?

Step 1: Open your project in Android mode then go to Gradle Scripts > build. gradle(Module: app) as shown in the following image. Step 2: Refer to the below image and here you have to change the minSdkVersion and targetSdkVersion as per the requirement.

Why API level is important?

Declaring a minimum API Level This ensures that users will only be able to install your application if their devices are running a compatible version of the Android platform. In turn, this ensures that your application can function properly on their devices.

What should be the minimum API level and why?

Starting in November 2022, app updates must target API level 31 or above and adjust for behavioral changes in Android 12; except for Wear OS apps, which must target API level 30 or higher.

What is @RequiresApi?

@RequiresApi - Denotes that the annotated element should only be called on the given API level or higher. @TargetApi - Indicates that Lint should treat this type as targeting a given API level, no matter what the project target is.


1 Answers

Add the line @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) above the method signature, where Build.VERSION_CODES.ICE_CREAM_SANDWICH evaluates to 14, the API version code for Ice Cream Sandwich.

Like so:

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public void yourMethod() {     if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {         getActionBar().setHomeButtonEnabled(false);     } } 
like image 155
Cat Avatar answered Sep 22 '22 14:09

Cat