0

My requirement is to check if the app has microphone access granted or not. If not then get the access. My app is built using Cordova. I have used https://github.com/edimuj/cordova-plugin-audioinput and https://github.com/dpa99c/cordova-diagnostic-plugin they work for Android and iOS devices except for XIAOMI devices. In XIAOMI devices I always get the permission has granted already but that is not true. Is there any Cordova plugin I can use which works in XIAOMI devices also?

Sample code using the audio input plugin

// First check whether we already have permission to access the microphone.
window.audioinput.checkMicrophonePermission(function(hasPermission) {
    if (!hasPermission) {
        // Ask the user for permission to access the microphone
        window.audioinput.getMicrophonePermission(function(hasPermission) {
            if (!hasPermission) {
                scope.showMicrophoneDeniedMsg = true;
            }
        });
    }
});

Sample code using the diagnostic plugin

cordova.plugins.diagnostic.getMicrophoneAuthorizationStatus(function(status) {
    if (status === cordova.plugins.diagnostic.permissionStatus.GRANTED) {
        console.log("Microphone use is authorized");
    } else {
        console.log("Microphone use is denied");
        cordova.plugins.diagnostic.requestMicrophoneAuthorization(function(status) {
            if (status === cordova.plugins.diagnostic.permissionStatus.GRANTED) {
                console.log("Microphone use is authorized");
            }
        }, function(error) {
            console.error(error);
            console.log("Microphone use is denied 1");
        });
    }
}, function(error) {
    console.error("The following error occurred: " + error);
});
Harish KV
  • 23
  • 1
  • 8

1 Answers1

0

Found what the problem is. I was adding the plugin in config.xml straight away like

<plugin name="cordova-plugin-audioinput" spec="1.0.1"/>

Now I have added for iOS and Android separately

<platform name="ios">
    <plugin name="cordova-plugin-audioinput" spec="1.0.1"/>
</platform>

<platform name="android">
    <plugin name="cordova-plugin-audioinput" spec="1.0.1"/>
</platform>

Works like a charm.

Harish KV
  • 23
  • 1
  • 8