-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
372 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
app/src/main/java/com/fingerprint/authentication/BiometricUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.fingerprint.authentication | ||
|
||
import android.Manifest | ||
import android.content.Context | ||
import android.content.pm.PackageManager | ||
import android.os.Build | ||
import android.support.v4.app.ActivityCompat | ||
import android.support.v4.hardware.fingerprint.FingerprintManagerCompat | ||
|
||
object BiometricUtils { | ||
|
||
|
||
val isBiometricPromptEnabled = Build.VERSION.SDK_INT > Build.VERSION_CODES.M | ||
|
||
|
||
/* | ||
* Condition I: Check if the android version in device is greater than | ||
* Marshmallow, since fingerprint authentication is only supported | ||
* from Android 6.0. | ||
* Note: If your project's minSdkversion is 23 or higher, | ||
* then you won't need to perform this check. | ||
* | ||
* */ | ||
val isSdkVersionSupported = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M | ||
|
||
|
||
/* | ||
* Condition II: Check if the device has fingerprint sensors. | ||
* Note: If you marked android.hardware.fingerprint as something that | ||
* your app requires (android:required="true"), then you don't need | ||
* to perform this check. | ||
* | ||
* */ | ||
fun isHardwareSupported(context: Context) = FingerprintManagerCompat.from(context).isHardwareDetected | ||
|
||
|
||
/* | ||
* Condition III: Fingerprint authentication can be matched with a | ||
* registered fingerprint of the user. So we need to perform this check | ||
* in order to enable fingerprint authentication | ||
* | ||
* */ | ||
fun isFingerprintAvailable(context: Context) = FingerprintManagerCompat.from(context).hasEnrolledFingerprints() | ||
|
||
|
||
/* | ||
* Condition IV: Check if the permission has been added to | ||
* the app. This permission will be granted as soon as the user | ||
* installs the app on their device. | ||
* | ||
* */ | ||
fun isPermissionGranted(context: Context): Boolean { | ||
return ActivityCompat.checkSelfPermission(context, Manifest.permission.USE_FINGERPRINT) == PackageManager.PERMISSION_GRANTED | ||
} | ||
|
||
} |
152 changes: 0 additions & 152 deletions
152
app/src/main/java/com/fingerprint/authentication/FingerprintActivity.java
This file was deleted.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
app/src/main/java/com/fingerprint/authentication/FingerprintActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.fingerprint.authentication | ||
|
||
import android.content.Intent | ||
import android.graphics.Color | ||
import android.os.Bundle | ||
import android.support.v7.app.AppCompatActivity | ||
import android.widget.Toast | ||
import kotlinx.android.synthetic.main.activity_fingerprint.* | ||
|
||
class FingerprintActivity : AppCompatActivity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_fingerprint) | ||
initTouchAuth() | ||
} | ||
|
||
private fun initTouchAuth() { | ||
val handler = FingerprintHandler(this) | ||
handler.initTouchAuth { code, message -> | ||
if (handler.isSuccess(code)) { | ||
Toast.makeText(this, message, Toast.LENGTH_LONG).show() | ||
startActivity(Intent(this, MainActivity::class.java)) | ||
finish() | ||
} else { | ||
errorText.setTextColor(Color.RED) | ||
errorText.text = message | ||
} | ||
} | ||
} | ||
} |
69 changes: 0 additions & 69 deletions
69
app/src/main/java/com/fingerprint/authentication/FingerprintHandler.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.