diff --git a/android/capacitor/src/main/java/com/getcapacitor/plugin/Permissions.java b/android/capacitor/src/main/java/com/getcapacitor/plugin/Permissions.java index 59ae8e20e..61583c8e6 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/plugin/Permissions.java +++ b/android/capacitor/src/main/java/com/getcapacitor/plugin/Permissions.java @@ -37,6 +37,8 @@ public void query(PluginCall call) { case "clipboard-read": case "clipboard-write": checkClipboard(call); + case "microphone": + checkMicrophone(call); break; default: call.reject("Unknown permission type"); @@ -80,4 +82,8 @@ private void checkClipboard(PluginCall call) { call.resolve(ret); } + private void checkMicrophone(PluginCall call) { + checkPerm(Manifest.permission.RECORD_AUDIO, call); + } + } diff --git a/core/src/core-plugin-definitions.ts b/core/src/core-plugin-definitions.ts index 94907eab6..115383460 100644 --- a/core/src/core-plugin-definitions.ts +++ b/core/src/core-plugin-definitions.ts @@ -1348,7 +1348,8 @@ export enum PermissionType { Geolocation = 'geolocation', Notifications = 'notifications', ClipboardRead = 'clipboard-read', - ClipboardWrite = 'clipboard-write' + ClipboardWrite = 'clipboard-write', + Microphone = 'microphone' } export interface PermissionsOptions { diff --git a/ios/Capacitor/Capacitor/Plugins/Permissions.swift b/ios/Capacitor/Capacitor/Plugins/Permissions.swift index 5ab819fe7..97b3ef419 100644 --- a/ios/Capacitor/Capacitor/Plugins/Permissions.swift +++ b/ios/Capacitor/Capacitor/Plugins/Permissions.swift @@ -25,6 +25,8 @@ public class CAPPermissionsPlugin: CAPPlugin { return checkClipboard(call) case "photos": return checkPhotos(call) + case "microphone": + return checkMicrophone(call) default: return call.reject("Unknown permission type") } @@ -108,4 +110,22 @@ public class CAPPermissionsPlugin: CAPPlugin { "state": "granted" ]) } + + func checkMicrophone(_ call: CAPPluginCall) { + let microStatus = AVCaptureDevice.authorizationStatus(for: .audio) + + var ret = "prompt" + switch (microStatus) { + case .authorized: + ret = "granted" + case .denied, .restricted: + ret = "denied" + case .notDetermined: + ret = "prompt" + } + + call.resolve([ + "state": ret + ]) + } }