RequiresApi和TargetApi有什么区别?
kotlin的样品:
@RequiresApi(api = Build.VERSION_CODES.M) @TargetApi(Build.VERSION_CODES.M) class FingerprintHandlerM() : FingerprintManager.AuthenticationCallback()
注意:FingerprintManager.AuthenticationCallback需要api M
注2:如果我不使用TargetApi lint失败与错误类需要api级别23 …
解决方法
类似于Mike所说,正如您在文档中可以看到的那样:
Denotes that the annotated element should only be called on the given API level or higher.
This is similar in purpose to the older @TargetApi annotation,but more clearly expresses that this is a requirement on the caller,rather than being used to “suppress” warnings within the method that exceed the minSdkVersion.