RequiresApi vs TargetApi android批注
问题描述:
RequiresApi
和TargetApi
有什么区别?
科特林样品:
@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,则皮棉会失败,并显示错误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.