Android 麦克风权限

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24817849/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 08:48:24  来源:igfitidea点击:

Microphone permission

androidpermissionsandroid-permissions

提问by deimos1988

When installing the app I programmed, it requires the permission "to use the microphone". I don't however specifically ask for it in the manifest, what I have is the camera permission.

安装我编写的应用程序时,它需要“使用麦克风”的权限。然而,我并没有在清单中特别要求它,我拥有的是相机许可。

Is that where the microphone-permission is coming from?

那是麦克风许可的来源吗?

回答by Nithinlal

<uses-permission android:name="android.permission.RECORD_AUDIO" />

outside the application block actually solved it!

外应用块居然解决了!

...
    </application>


    <uses-permission android:name="android.permission.RECORD_AUDIO" /> 
</manifest>

回答by GrIsHu

If you are using any kind of audio recording functionality in your application then you are supposed to provide RECORD_AUDIOpermission in your manifest file as below:

如果您在应用程序中使用任何类型的录音功能,那么您应该RECORD_AUDIO在清单文件中提供如下权限:

 <uses-permission android:name="android.permission.RECORD_AUDIO" />

回答by Mohammad reza Khodabandeh

Since Android 6.0 Marshmallow, application will not be granted any permission at installation time. Instead, application has to ask user for a permission one-by-one at runtime. Please note that permission request dialog shown above will not launch automatically. Developer has to call for it manually. In the case that developer try to call some function that requires a permission which user has not granted yet, the function will suddenly throw an Exception which will lead to the application crashing.

从 Android 6.0 Marshmallow 开始,应用程序在安装时不会被授予任何权限。相反,应用程序必须在运行时逐一询问用户权限。请注意,上面显示的权限请求对话框不会自动启动。开发人员必须手动调用它。如果开发者尝试调用某个需要用户尚未授予权限的函数,该函数会突然抛出异常,从而导致应用程序崩溃。

also add this to manifest:

还要将此添加到清单中:

<uses-permission android:name="android.permission.RECORD_AUDIO" />

回答by Hansel

in your manifest use this

在你的清单中使用这个

 <uses-permission android:name="android.permission.RECORD_AUDIO" />

Then to request the permission do this:

然后请求权限这样做:

if (ContextCompat.checkSelfPermission(getActivity(),
    Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {

ActivityCompat.requestPermissions(getActivity(),
        new String[]{Manifest.permission.RECORD_AUDIO},
        REQUEST_MICROPHONE);

}

}