我的要求是检查应用程序是否已授予麦克风访问权限。如果没有,则获得访问权限。我的应用程序是使用 Cordova 构建的。我使用了https://github.com/edimuj/cordova-plugin-audioinput和https://github.com/dpa99c/cordova-diagnostic-plugin,它们适用于除 XIAOMI 设备之外的 Android 和 iOS 设备。在 XIAOMI 设备中,我总是获得已经授予的权限,但事实并非如此。是否有任何我可以使用的 Cordova 插件也适用于 XIAOMI 设备?
使用音频输入插件的示例代码
// 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;
}
});
}
});
使用诊断插件的示例代码
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);
});