Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What permission I need in order to use camera flash in camera preview?

I have a custom camera application and I need to be able to turn flash on(torch mode actually)/off.

What kind of permission do I need in this case?

1.Only

<uses-feature android:name="android.hardware.camera"/>    
<uses-permission android:name="android.permission.CAMERA"/>

2. Those from 1 plus:

<permission android:name="android.permission.FLASHLIGHT"
     android:permissionGroup="android.permission-group.HARDWARE_CONTROLS"
     android:protectionLevel="normal"/>

I think this is used when you want to use Flash, but without camera (like in this case: Android - Using Camera Flash)

3.Those from 1 plus:

<uses-permission android:name="android.hardware.camera.flash"/>

EDITED (thanks to @maclir):

Above line is incorrect. The correct one is:

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

developer.android.com: "Subfeature. The application uses the device camera's flash." (http://developer.android.com/guide/topics/manifest/uses-feature-element.html)

In all 3 cases, tested on 2 devices, works ok - I can activate/deactivate flash, but I want to be sure what exactly each of them means. It is weird that even without option 3 it is working ok...for what is than used option 3?

I think I'm missing something...

ANSWER

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

is mandatory in order to use the camera (I'm not using camera via Intent, I have a customize camera app)

and:

<uses-feature android:name="android.hardware.camera" android:required="false"/>
<uses-feature android:name="android.hardware.camera.flash" android:required="false" />

are the camera specific features I use in the app.

android:required="false" means Google Play will not prevent the application from being installed to devices that do not include these camera features - so the user having a device without camera and camera flash will be able to install the app from market.

http://developer.android.com/reference/android/hardware/Camera.html

like image 599
Paul Avatar asked Jul 10 '13 16:07

Paul


People also ask

What is the permission for using the camera Android permission?

On your phone, open the Settings app. Tap Privacy. Turn off Camera access or Microphone access.

What is permission for using camera?

Camera Permission - Your application must request permission to use a device camera. Note: If you are using the camera by invoking an existing camera app, your application does not need to request this permission. For a list of camera features, see the manifest Features Reference.

How do I get camera permission?

Enable camera on an Android deviceOpen the “Settings” app. Tap “Apps & notifications”. Tap “Merge Explorer” or “Object Viewer” (both need permission). Tap “Permissions”, then choose the “Camera” permission to enable.


1 Answers

According to android developers permission-group:

Note that this element does not declare a permission itself, only a category in which permissions can be placed. See the <permission> element for information on declaring permissions and assigning them to groups

You would need two permissions Manifest.permission:

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

to be able to access the camera and the flashlight.

And you would need to declares the hardware features that is used by the application (camera and flash) Features Reference:

<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-feature android:name="android.hardware.camera.flash" android:required="false" />

android:required indicates whether phones not having these hardware can install your application or not.

On your third point, I think you have a type because uses-permission tag can not be used with android.hardware...

<uses-permission android:name="android.hardware.camera.flash"/>
like image 138
maclir Avatar answered Oct 09 '22 08:10

maclir