Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Mobile Dev

Nav Singh navczydev

💭
Mobile Dev
View GitHub Profile
View AndroidManifest.xml
<uses-permission android:name="android.permission.USE_BIOMETRIC"/>
View BiometricDependency.gradle
implementation "androidx.biometric:biometric:1.1.0"
View GetBiometricLabels.kt
val biometricManager = BiometricManager.from(this)
var result = listOf<String?>()
if (biometricManager.canAuthenticate(BIOMETRIC_STRONG) == BiometricManager.BIOMETRIC_SUCCESS) {
when {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
val bioMetricHardwareManager = (applicationContext.getSystemService(Context.BIOMETRIC_SERVICE) as? android.hardware.biometrics.BiometricManager)
bioMetricHardwareManager?.getStrings(Authenticators.BIOMETRIC_WEAK or Authenticators.BIOMETRIC_STRONG)
?.run {
result = listOf(
View Different messages based.kt
Results from Samsung S21 Ultra
When user has only face id:
[Use Face Unlock,
Use your face to continue,
Use biometrics]
When user has only fingerprint:
View CreateNotification.kt
package com.example.myapplication
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent.FLAG_IMMUTABLE
import android.content.Context
import android.os.Build
import androidx.core.app.NotificationCompat
import androidx.core.app.TaskStackBuilder
View MainActivity.kt
package com.example.myapplication
import android.Manifest
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.provider.Settings
View AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.myapplication">
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<application>
</application>
</manifest>
View Notification value
public static final String POST_NOTIFICATIONS = "android.permission.POST_NOTIFICATIONS";
View BaseApplication.kt
/**
* Used to demo the foreground service restrictions
*
*/
class BaseApplication : Application(), LifecycleEventObserver {
override fun onCreate() {
super.onCreate()
ProcessLifecycleOwner.get().lifecycle.addObserver(this)
}
View ForegroundService.kt
class ForegroundService : Service() {
override fun onCreate() {
super.onCreate()
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val serviceChannel = NotificationChannel(