Skip to content

Commit

Permalink
Android P support
Browse files Browse the repository at this point in the history
  • Loading branch information
nimish17 committed Feb 12, 2019
1 parent e111489 commit 893cac0
Show file tree
Hide file tree
Showing 11 changed files with 372 additions and 238 deletions.
21 changes: 10 additions & 11 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
compileSdkVersion 28
defaultConfig {
applicationId "com.fingerprint.authentication"
minSdkVersion 23
targetSdkVersion 25
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
Expand All @@ -20,10 +20,9 @@ android {
}

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'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
}
11 changes: 9 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.fingerprint.authentication">

<!-- Step 1: Add the following permission to the app -->
<uses-permission android:name="android.permission.USE_BIOMETRIC" />

<!-- Step 2: This permission is depreciated in Android P -->
<uses-permission android:name="android.permission.USE_FINGERPRINT" />

<application
Expand All @@ -10,7 +14,8 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".FingerprintActivity"
<activity
android:name=".FingerprintActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand All @@ -19,7 +24,9 @@
</intent-filter>
</activity>


<activity
android:name=".MainActivity"
android:screenOrientation="portrait" />
</application>

</manifest>
56 changes: 56 additions & 0 deletions app/src/main/java/com/fingerprint/authentication/BiometricUtils.kt
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
}

}

This file was deleted.

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
}
}
}
}

This file was deleted.

Loading

0 comments on commit 893cac0

Please sign in to comment.