From 556d36ce07418035ba9d05ea7e42a1f218341b7c Mon Sep 17 00:00:00 2001 From: Inhishonor Date: Wed, 19 Feb 2025 13:36:55 -0800 Subject: [PATCH] Add error message to double tap function as well. --- .../QKSMS/feature/compose/ComposeActivity.kt | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeActivity.kt b/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeActivity.kt index 31b4b161..c7f0b227 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeActivity.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeActivity.kt @@ -199,13 +199,22 @@ class ComposeActivity : QkThemedActivity(), ComposeView { private var lastUpEvent: MotionEvent? = null override fun onDoubleTap(e: MotionEvent): Boolean { + // Create the speech recognizer intent val speechRecognizerIntent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH) - .putExtra( - RecognizerIntent.EXTRA_LANGUAGE_MODEL, - RecognizerIntent.LANGUAGE_MODEL_FREE_FORM - ) - // include if want a custom message that the STT can (optionally) display .putExtra(RecognizerIntent.EXTRA_PROMPT, "Speak your message") - speechResultLauncher.launch(speechRecognizerIntent) + .putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM) + // Optionally include a prompt message + .putExtra(RecognizerIntent.EXTRA_PROMPT, "Speak your message") + + // Check if there is a speech recognition service available + val resolveInfoList = packageManager.queryIntentActivities(speechRecognizerIntent, PackageManager.MATCH_DEFAULT_ONLY) + + if (resolveInfoList.isEmpty()) { + // No STT provider found, show a Toast message + Toast.makeText(this@ComposeActivity, "No speech-to-text service available on this device.", Toast.LENGTH_SHORT).show() + } else { + // Launch the speech recognizer + speechResultLauncher.launch(speechRecognizerIntent) + } return true }