RequiresApi vs TargetApi android批注 [英] RequiresApi vs TargetApi android annotations

查看:186
本文介绍了RequiresApi vs TargetApi android批注的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

RequiresApiTargetApi有什么区别?

科特林样品:

@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.

这篇关于RequiresApi vs TargetApi android批注的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆