Skip to content

Commit 26054a5

Browse files
bryanloganalexzfp
andcommitted
MOBILE-707: demo update (#46)
Co-authored-by: Alex Z. <[email protected]>
1 parent b7b41ae commit 26054a5

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
xmlns:tools="http://schemas.android.com/tools">
44

55
<uses-sdk tools:overrideLibrary="androidx.security" />
6-
6+
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
7+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
78
<application
89
android:name=".App"
910
android:allowBackup="false"

app/src/main/java/com/fingerprintjs/android/fpjs_pro_demo/MainActivity.kt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
package com.fingerprintjs.android.fpjs_pro_demo
22

3+
import android.Manifest
34
import android.animation.ObjectAnimator
5+
import android.content.pm.PackageManager
46
import android.os.Build
57
import android.os.Bundle
68
import android.view.View
79
import android.view.animation.AccelerateInterpolator
810
import androidx.activity.ComponentActivity
911
import androidx.activity.compose.setContent
12+
import androidx.activity.result.contract.ActivityResultContracts
1013
import androidx.core.animation.doOnEnd
14+
import androidx.core.app.ActivityCompat
1115
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
1216
import com.fingerprintjs.android.fpjs_pro_demo.ui.navigation.NavScreen
1317
import com.fingerprintjs.android.fpjs_pro_demo.ui.theme.AppTheme
@@ -37,5 +41,40 @@ class MainActivity : ComponentActivity() {
3741
NavScreen()
3842
}
3943
}
44+
45+
checkLocationPermissions()
46+
}
47+
48+
fun checkLocationPermissions() {
49+
if (isAnyLocationPermissionGranted()) {
50+
// We have at least some location permission, so we can proceed with Fingerprint call
51+
return
52+
}
53+
54+
val locationPermissionRequest = registerForActivityResult(
55+
ActivityResultContracts.RequestMultiplePermissions()
56+
) { permissions ->
57+
// Even if the user didn't give us permission, we now know the answer and therefore
58+
// should proceed with the Fingerprint call
59+
}
60+
61+
locationPermissionRequest.launch(
62+
arrayOf(
63+
Manifest.permission.ACCESS_FINE_LOCATION,
64+
Manifest.permission.ACCESS_COARSE_LOCATION
65+
)
66+
)
67+
}
68+
69+
private fun isAnyLocationPermissionGranted(): Boolean {
70+
return isPermissionGranted(Manifest.permission.ACCESS_FINE_LOCATION) ||
71+
isPermissionGranted(Manifest.permission.ACCESS_COARSE_LOCATION)
72+
}
73+
74+
private fun isPermissionGranted(permission: String): Boolean {
75+
return ActivityCompat.checkSelfPermission(
76+
this,
77+
permission
78+
) == PackageManager.PERMISSION_GRANTED
4079
}
4180
}

app/src/main/java/com/fingerprintjs/android/fpjs_pro_demo/domain/identification/IdentificationProvider.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class IdentificationProvider @Inject constructor(
3434
apiKey = if (it.enabled) it.public else Credentials.apiKey,
3535
endpointUrl = if (it.enabled) it.region.endpointUrl else Credentials.endpointUrl,
3636
extendedResponseFormat = true,
37+
locationTimeoutMillis = 30_000L,
38+
allowUseOfLocationData = true,
3739
)
3840
)
3941
}

gradle/libs.versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ dagger = "2.51.1"
1717
junit = "4.13.2"
1818
junitExt = "1.2.1"
1919
espresso = "3.6.1"
20-
fingerprint = "2.9.0"
21-
fingerprintDebug = "2.9.0-debug"
20+
fingerprint = "2.10.0"
21+
fingerprintDebug = "2.10.0-debug"
2222
androidApplicationPlugin = "8.7.1"
2323
kotlin = "2.0.21"
2424
detekt = "1.23.8"

0 commit comments

Comments
 (0)