Checking the Android Version on device at runtime
suggest changeBuild.VERSION_CODES is an enumeration of the currently known SDK version codes.
To run code only on certain Android versions, check Build.VERSION.SDK_INT before calling APIs that did not exist on older devices. TargetApi tells Lint that the guarded call is intentional.
FingerprintManager and Context.getSystemService(Class) were added in API 23. The check must be >=, so the call does not run on older devices:
@Override
@TargetApi(23)
public void onResume() {
super.onResume();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
FingerprintManager fingerprintManager = this.getSystemService(FingerprintManager.class);
//......................
}
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents