Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(android): replace deprecated hasPermission #98

Merged
merged 2 commits into from
Jun 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,14 @@
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 +73,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 +149,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
Loading