如何在android中获得相机的权限.(特别是棉花糖) [英] How get permission for camera in android.(Specifically Marshmallow)
问题描述
嘿,我正在 android studio 中设计一个应用程序.在其中我需要相机的许可.我已经包含了 <uses-permission android:name="android.permission.CAMERA"/>
在 AndroidManifest.xml 文件中.它在除 Marshmallow 之外的所有版本的 android 中都能正常工作.我如何默认获得相机权限?如果不可能,我该如何向用户询问?
Hey I am designing an app in android studio. In which i require permission of camera. I have included <uses-permission android:name="android.permission.CAMERA" />
in the the AndroidManifest.xml file. It is working properly in all versions of android except Marshmallow. How do I get camera permission by default? If not possible how do I ask it from user?
推荐答案
先检查用户是否授予权限:
First check if the user has granted the permission:
if (ContextCompat.checkSelfPermission(context, Manifest.permission.CAMERA)
== PackageManager.PERMISSION_DENIED)
然后,您可以使用它向用户请求:
Then, you could use this to request to the user:
ActivityCompat.requestPermissions(activity, new String[] {Manifest.permission.CAMERA}, requestCode);
而在 Marshmallow 中,它会出现在一个对话框中
And in Marshmallow, it will appear in a dialog
这篇关于如何在android中获得相机的权限.(特别是棉花糖)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!