Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何向Java应用程序(macOS Mojave及以上)授予麦克风权限?_Java_Swift_Xcode_Command Line - Fatal编程技术网

如何向Java应用程序(macOS Mojave及以上)授予麦克风权限?

如何向Java应用程序(macOS Mojave及以上)授予麦克风权限?,java,swift,xcode,command-line,Java,Swift,Xcode,Command Line,我已经在xcode(swift 4+)中创建了一个可执行文件。我已经在项目(.plist文件)中添加了麦克风权限,并且还请求了运行时权限:以下是代码: switch AVCaptureDevice.authorizationStatus(for: .audio) { case .authorized: audioStarter.staticMode() case .notDetermined: AVCaptureDevice.requestAcc

我已经在xcode(swift 4+)中创建了一个可执行文件。我已经在项目(.plist文件)中添加了麦克风权限,并且还请求了运行时权限:以下是代码:

switch AVCaptureDevice.authorizationStatus(for: .audio) {
    case .authorized:
        audioStarter.staticMode()

    case .notDetermined:
        AVCaptureDevice.requestAccess(for: .audio) { granted in
            if granted {
                print("Permission granted")
                audioStarter.staticMode()
            }
        }

    case .denied:
        print("Permission denied")
        exit(0)

    case .restricted:
        print("This user cannot access microphone")
        exit(0)
    }
如果我通过终端运行它,这个可执行文件工作正常(它显示麦克风权限弹出窗口,工作绝对正常)。但当我从Java进程运行这个exec文件时,它不显示访问麦克风的权限,因此exec文件不工作。以下是java中的示例代码:

String cmd = getBinPath() + "./audio_service -r";
        try {
            final Process p = Runtime.getRuntime().exec(cmd);
            Scanner scanner = new Scanner(p.getInputStream());
            while (scanner.hasNextLine()) {
                String response = scanner.nextLine ();
                System.out.println(response);
            }
        }
        catch (Exception e) {
            e.printStackTrace();
        }

嗨,你找到解决办法了吗?我被同样的问题难住了。我有两套Mac OS Catalina系统。Java不会在两个系统上都请求权限。然而,在一个系统上,我能够访问麦克风并能够录制,而在另一个系统上,它无法检测麦克风中的声音。如果你有解决方案,请分享。嗨。我在xcode项目中添加了info.plist文件,并在其中添加了麦克风依赖项(权限)。之后,它会显示麦克风权限弹出窗口。