RequiresApi 与 TargetApi android 注释 [英] RequiresApi vs TargetApi android annotations
本文介绍了RequiresApi 与 TargetApi android 注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
RequiresApi
和 TargetApi
有什么区别?
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.
这篇关于RequiresApi 与 TargetApi android 注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文