Skip to content

Commit

Permalink
refactor(android): replace deprecated hasPermission
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile committed Jun 7, 2024
1 parent 5ea16bb commit 0d48b68
Showing 1 changed file with 4 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 0d48b68

Please sign in to comment.