ifApi

inline fun <T> ifApi(level: Int, fallback: T, block: () -> T): T

Runs block only when the platform is at least SDK level, returning fallback otherwise or if block throws.

Return

The block result, or fallback.

Parameters

level

Minimum SDK level required to attempt block.

fallback

Value returned when the API is unavailable or the block fails.

block

Work to run when the API level is satisfied.