RequiresCarApi

public abstract @interface RequiresCarApi
implements Annotation

androidx.car.app.annotations.RequiresCarApi


Defines the minimum API level required to be able to use this model, field, or method.

Before using any of these elements, application must check that CarContext.getCarAppApiLevel() is equal or greater than the value of this annotation.

For example, if an application wants to use a newer template "Foo" marked with @RequiresCarApi(2) while maintain backwards compatibility with older hosts by using an older template "Bar" (@RequiresHostApiLevel(1)), they can do:

 if (getCarContext().getCarApiLevel() >= 2) {
     // Use new feature
     return Foo.Builder()....;
 } else {
     // Use supported fallback
     return Bar.Builder()....;
 }
 
If a certain model or method has no RequiresCarApi annotation, it is assumed to be available in all car API levels.

API stability

New APIs that are introduced during alpha library releases should be used with extra caution. Specifically, apps should NOT use APIs in the following categories in their production APKs:
  • New APIs that are only available in alpha releases
  • APIs that are annotated with ExperimentalCarApi

As they are considered unstable or experimental, these APIs may change and potentially break your app when the host(s) are updated.

Summary

Public methods

int value()

The minimum API level required to be able to use this model, field or method.

Inherited methods

Public methods

value

public int value ()

The minimum API level required to be able to use this model, field or method. Applications shouldn't use any elements annotated with a RequiresCarApi greater than CarContext.getCarAppApiLevel()

Returns
int