Is there an annotation that denotes a max Android API version?

Viewed 320

The annotation @RequiresApi is helpful for requiring that the annotated element is only called on the given API level or higher. However, there does not appear to be a corresponding annotation for requiring that the annotated element is only called on the given API or lower.

For example, given something like:

@RequiresMaxApi(28) // or @DeprecatedSinceAndroid(29)
fun doSomethingWithExternalStorage() {
    val dir = Environment.getExternalStorageDirectory() // This is deprecated in API 29
    // ...
}

Calling doSomethingWithExternalStorage() from code that does not include a check like:

if (VERSION.SDK_INT < 29) {
    doSomethingWithExternalStorage()
}

Without the above API check, doSomethingWithExternalStorage() would display a lint error/warning, similar to how @RequiresApi does.

From my understanding, this is also similar to how @DeprecatedSinceKotlin works.

Is there an existing annotation that meets these requirements, or is there another way to achieve the desired result?

0 Answers
Related