我想使用面部解锁作为我的应用程序的第二个因素,因为我的大多数用户不会用密码锁定他们的手机。
Android应用中有没有集成人脸解锁的Android API?
有一些用于照片识别的人脸检测API,但我找不到可以在离线场景中使用的API,特别是对于应用程序中的其他因素。
如果你需要一个真实的例子,假设这是一个密码管理器,或者电话将被借给一个孩子……而且店主从来不把手机锁起来。面孔解锁将确保他们需要隐私的东西。
发布于 2015-08-10 00:03:01
对于那些不喜欢阅读的人来说,
: OpenCV可以在面部识别方面实现您正在寻找的所有东西。(文档here)
这是一个很难回答的问题,因为几乎没有现有的android应用程序使用您所要求的面部识别技术。但是,您可能希望查看以下站点:
A good list of face detection software
A decent walkthrough for some of the main api's available
Another higher quality tutorial...
Documentation for default android FaceDetector class
It might be useful to take a look at this sample which uses the OpenCV library
我理解离线无法完成此任务的问题。为了解决这个问题,你总是可以添加一个“备份”,比如一个普通的密码,只有在发现用户没有互联网接入时才会生效。另一种解决方案是简单地要求你的应用程序有一个稳定的互联网/蜂窝连接。
编辑:不幸的是,
Face unlock是封闭源代码的谷歌专有代码,因此我们没有机会对其进行修改。来源:http://forum.xda-developers.com/showthread.php?t=1367610
您可能正在寻找以下信息:
最流行的图像操纵和类似的库似乎是OpenCV,它有一个可以在here中找到的Java包装器
您还需要它在后台运行,定期检查用户的脸,而不是指示正在发生这种情况,因此在选择库/方法时,您应该记住这一点
来源:不久前,我实现了人脸识别技术,作为用户登录我的一个应用程序的一种方式,所以我只是在讲述我在搜索这个问题的答案时所记得的事情
您的场景:
如果你需要一个真实的例子,假设这是一个密码管理器,或者手机将被借给一个孩子……而且店主从来不把手机锁起来。面孔解锁将确保他们需要隐私的东西。
至于实现这一点,我会阅读android加密,如果这就是你所说的“保护他们需要隐私的东西”的意思。否则,如果您只想使用人脸识别而不是密码来创建某种“应用锁”,这就简单多了,可以使用intents/基本if语句等来完成(我假设您是使用Java完成的)。
请随时提问。目前,我正在寻找我的旧源代码,在那里我做了一些类似于你想要的东西,但我怀疑我是否还拥有它……
更新:查看this ...是的,OpenCV可以离线使用,所以我想这就是你们要找的
发布于 2020-07-02 18:54:33
目前,你可以使用生物识别API,它可以在幕后检查设备上可用的生物识别类型(面部解锁或指纹),并将执行所有操作,包括处理许多硬件特定的问题。
因此,从添加依赖项开始:
implementation 'androidx.biometric:biometric:1.0.1'您可以通过以下方式查看可用性:
val biometricManager = BiometricManager.from(this)
when (biometricManager.canAuthenticate()) {
BiometricManager.BIOMETRIC_SUCCESS ->
// App can authenticate using biometrics
BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE ->
// No biometric features available on this device
BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE ->
// Biometric features are currently unavailable
BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED ->
// The user hasn't associated any biometric credentials with their account
}使用为您提供的系统对话框:
private lateinit var executor: Executor
private lateinit var biometricPrompt: BiometricPrompt
private lateinit var promptInfo: BiometricPrompt.PromptInfo
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login)
executor = ContextCompat.getMainExecutor(this)
biometricPrompt = BiometricPrompt(this, executor,
object : BiometricPrompt.AuthenticationCallback() {
override fun onAuthenticationError(errorCode: Int,
errString: CharSequence) {
super.onAuthenticationError(errorCode, errString)
// Authentication error
}
override fun onAuthenticationSucceeded(
result: BiometricPrompt.AuthenticationResult) {
super.onAuthenticationSucceeded(result)
// Authentication succeeded!
}
override fun onAuthenticationFailed() {
super.onAuthenticationFailed()
// Authentication failed
}
})
promptInfo = BiometricPrompt.PromptInfo.Builder()
.setTitle("Biometric login for my app")
.setSubtitle("Log in using your biometric credential")
.setNegativeButtonText("Use account password")
.build()
// Prompt appears when user clicks "Log in".
// Consider integrating with the keystore to unlock cryptographic operations,
// if needed by your app.
biometricLoginButton.setOnClickListener {
biometricPrompt.authenticate(promptInfo)
}
}如果你想让你的应用程序解锁,在解锁面部后按下确认按钮(例如,当用户执行购买时)-这是默认行为。如果您想在没有确认的情况下立即解锁应用程序:
//允许用户在接受其生物识别凭据后无需执行任何操作即可进行身份验证。
promptInfo = BiometricPrompt.PromptInfo.Builder()
.setTitle("Biometric login for my app")
.setSubtitle("Log in using your biometric credential")
.setNegativeButtonText("Use account password")
.setConfirmationRequired(false)
.build()

此外,您可能需要为用户设置回退以使用设备pin/密码/模式解锁。它通过以下方式完成:
promptInfo = BiometricPrompt.PromptInfo.Builder()
.setTitle("Biometric login for my app")
.setSubtitle("Log in using your biometric credential")
// Cannot call setNegativeButtonText() and
// setDeviceCredentialAllowed() at the same time.
// .setNegativeButtonText("Use account password")
.setDeviceCredentialAllowed(true)
.build()有关加密技术的更多信息和详细信息可在此处找到:https://developer.android.com/training/sign-in/biometric-auth
https://stackoverflow.com/questions/18887994
复制相似问题