RequiresApi 与 TargetApi android 注释

RequiresApi 与 TargetApi android 注释

问题描述:

RequiresApiTargetApi 有什么区别?

kotlin 中的示例:

Sample in kotlin:

@RequiresApi(api = Build.VERSION_CODES.M)
@TargetApi(Build.VERSION_CODES.M)
class FingerprintHandlerM() : FingerprintManager.AuthenticationCallback()

注意:FingerprintManager.AuthenticationCallback 需要 api M

NOTE: FingerprintManager.AuthenticationCallback requires api M

注意 2:如果我不使用 TargetApi lint 失败并出现错误 class requires api level 23...

@RequiresApi - 表示注解元素只能在给定的 API 级别或更高级别上调用.

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

@TargetApi - 指示 Lint 应将此类型视为针对给定的 API 级别,无论项目目标是什么.

@TargetApi - Indicates that Lint should treat this type as targeting a given API level, no matter what the project target is.