方法isHardwareDetected()和hasEnrolledFingerprints()始终返回false。我发现目标 API 24 工作正常,所以这只是 25 的问题。我想使用最新的 API,但没有工作指纹是不可能的。
Activity
FingerprintManagerCompat from = FingerprintManagerCompat.from(getApplication());
boolean hardwareDetected = from.isHardwareDetected();
boolean b = from.hasEnrolledFingerprints();
应用程序.gradle
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.tkuhn.myapplication"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.2.0'
testCompile 'junit:junit:4.12'
}
最佳答案
使用最好的 FingerprintManager
和 FingerprintManagerCompat
。
对旧设备使用 FingerprintManagerCompat
的 isHardwareDetected ,对新设备使用 FingerprintManager
的 isHardwareDetected 。
private boolean isSensorAvialable() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
return ActivityCompat.checkSelfPermission(AppContext, Manifest.permission.USE_FINGERPRINT) == PackageManager.PERMISSION_GRANTED &&
AppContext.getSystemService(FingerprintManager.class).isHardwareDetected();
} else {
return FingerprintManagerCompat.from(AppContext).isHardwareDetected();
}
}
关于android - FingerprintManagerCompat isHardwareDetected 在 targetAPI 25 中返回 false,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42575967/