Skip to content

Commit

Permalink
Adding Android permission functions
Browse files Browse the repository at this point in the history
  • Loading branch information
msschwartz committed Nov 18, 2024
1 parent 257859c commit eb14871
Showing 1 changed file with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.os.Handler
import android.provider.Settings
import android.speech.ModelDownloadListener
Expand All @@ -16,6 +17,7 @@ import android.speech.RecognizerIntent
import android.speech.SpeechRecognizer
import android.util.Log
import androidx.annotation.RequiresApi
import expo.modules.interfaces.permissions.PermissionsResponse
import expo.modules.interfaces.permissions.Permissions.askForPermissionsWithPermissionsManager
import expo.modules.interfaces.permissions.Permissions.getPermissionsWithPermissionsManager
import expo.modules.kotlin.Promise
Expand Down Expand Up @@ -143,6 +145,46 @@ class ExpoSpeechRecognitionModule : Module() {
)
}

AsyncFunction("requestMicrophonePermissionsAsync") { promise: Promise ->
askForPermissionsWithPermissionsManager(
appContext.permissions,
promise,
RECORD_AUDIO,
)
}

AsyncFunction("getMicrophonePermissionsAsync") { promise: Promise ->
getPermissionsWithPermissionsManager(
appContext.permissions,
promise,
RECORD_AUDIO,
)
}

AsyncFunction("getSpeechRecognizerPermissionsAsync") { promise: Promise ->
Log.w("ExpoSpeechRecognitionModule", "getSpeechRecognizerPermissionsAsync is not supported on Android. Returning a granted permission response.")
promise.resolve(
Bundle().apply {
putString(PermissionsResponse.EXPIRES_KEY, "never")
putString(PermissionsResponse.STATUS_KEY, "granted")
putBoolean(PermissionsResponse.CAN_ASK_AGAIN_KEY, false)
putBoolean(PermissionsResponse.GRANTED_KEY, true)
}
)
}

AsyncFunction("requestSpeechRecognizerPermissionsAsync") { promise: Promise ->
Log.w("ExpoSpeechRecognitionModule", "requestSpeechRecognizerPermissionsAsync is not supported on Android. Returning a granted permission response.")
promise.resolve(
Bundle().apply {
putString(PermissionsResponse.EXPIRES_KEY, "never")
putString(PermissionsResponse.STATUS_KEY, "granted")
putBoolean(PermissionsResponse.CAN_ASK_AGAIN_KEY, false)
putBoolean(PermissionsResponse.GRANTED_KEY, true)
}
)
}

AsyncFunction("getStateAsync") { promise: Promise ->
val state =
when (expoSpeechService.recognitionState) {
Expand Down

0 comments on commit eb14871

Please sign in to comment.