akshayrajkore akshayrajkore - 6 months ago 34
Android Question

Is there @minApi annotation, analogous to @TargetApi annotation in Android?

int API_VERSION = 21;

@TargetApi(API_VERSION) is used in Android to specify that the method/class is supported for API_VERSION and below.

Can we mirror something similar which specifies that a method or class is supported for API_VERSION and above only?

Note:- I did not find any such annotation, but would like to ask the community is they have come across something like this or have implemented their own annotation?


There is @RequiresApi:

Denotes that the annotated element should only be called on the given API level or higher.

This is similar in purpose to the older @TargetApi annotation, but more clearly expresses that this is a requirement on the caller, rather than being used to "suppress" warnings within the method that exceed the minSdkVersion.