From 0d48b68c956bfeb8848ab489d9013144363aeefa Mon Sep 17 00:00:00 2001 From: jcesarmobile Date: Fri, 7 Jun 2024 17:48:38 +0200 Subject: [PATCH 1/2] refactor(android): replace deprecated hasPermission --- .../speechrecognition/SpeechRecognition.java | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/android/src/main/java/com/getcapacitor/community/speechrecognition/SpeechRecognition.java b/android/src/main/java/com/getcapacitor/community/speechrecognition/SpeechRecognition.java index e60458b..4caaaa5 100644 --- a/android/src/main/java/com/getcapacitor/community/speechrecognition/SpeechRecognition.java +++ b/android/src/main/java/com/getcapacitor/community/speechrecognition/SpeechRecognition.java @@ -12,6 +12,7 @@ import com.getcapacitor.JSArray; import com.getcapacitor.JSObject; import com.getcapacitor.Logger; +import com.getcapacitor.PermissionState; import com.getcapacitor.Plugin; import com.getcapacitor.PluginCall; import com.getcapacitor.PluginMethod; @@ -24,11 +25,12 @@ import java.util.concurrent.locks.ReentrantLock; import org.json.JSONArray; -@CapacitorPlugin(permissions = { @Permission(strings = { Manifest.permission.RECORD_AUDIO }, alias = "speechRecognition") }) +@CapacitorPlugin(permissions = { @Permission(strings = { Manifest.permission.RECORD_AUDIO }, alias = SpeechRecognition.SPEECH_RECOGNITION ) }) public class SpeechRecognition extends Plugin implements Constants { public static final String TAG = "SpeechRecognition"; private static final String LISTENING_EVENT = "listeningState"; + static final String SPEECH_RECOGNITION = "speechRecognition"; private Receiver languageReceiver; private SpeechRecognizer speechRecognizer; @@ -69,7 +71,7 @@ public void start(PluginCall call) { return; } - if (!hasAudioPermissions(RECORD_AUDIO_PERMISSION)) { + if (getPermissionState(SPEECH_RECOGNITION) != PermissionState.GRANTED) { call.reject(MISSING_PERMISSION); return; } @@ -145,14 +147,6 @@ private boolean isSpeechRecognitionAvailable() { return SpeechRecognizer.isRecognitionAvailable(bridge.getContext()); } - private boolean hasAudioPermissions(String type) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { - return true; - } - - return hasPermission(type); - } - private void listening(boolean value) { this.listening = value; } From 72beba1c6ff23c0c63aff0f432526c376f89c172 Mon Sep 17 00:00:00 2001 From: jcesarmobile Date: Fri, 7 Jun 2024 17:50:41 +0200 Subject: [PATCH 2/2] fmt --- .../community/speechrecognition/SpeechRecognition.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/com/getcapacitor/community/speechrecognition/SpeechRecognition.java b/android/src/main/java/com/getcapacitor/community/speechrecognition/SpeechRecognition.java index 4caaaa5..0f3fcab 100644 --- a/android/src/main/java/com/getcapacitor/community/speechrecognition/SpeechRecognition.java +++ b/android/src/main/java/com/getcapacitor/community/speechrecognition/SpeechRecognition.java @@ -25,7 +25,9 @@ import java.util.concurrent.locks.ReentrantLock; import org.json.JSONArray; -@CapacitorPlugin(permissions = { @Permission(strings = { Manifest.permission.RECORD_AUDIO }, alias = SpeechRecognition.SPEECH_RECOGNITION ) }) +@CapacitorPlugin( + permissions = { @Permission(strings = { Manifest.permission.RECORD_AUDIO }, alias = SpeechRecognition.SPEECH_RECOGNITION) } +) public class SpeechRecognition extends Plugin implements Constants { public static final String TAG = "SpeechRecognition";