19

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

Community
  • 1
  • 1
Paul
  • 3,812
  • 10
  • 50
  • 73
  • I think option 3 is used best for the use of camera and autofocus. – Niko Jul 10 '13 at 17:07
  • https://android.googlesource.com/platform/frameworks/native/+/master/data/etc/android.hardware.camera.flash-autofocus.xml – Niko Jul 10 '13 at 17:08

2 Answers2

34

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"/>
Pang
  • 9,564
  • 146
  • 81
  • 122
maclir
  • 3,218
  • 26
  • 39
3

Maclir answer is showing all the detail of permission required to use camera and its flash light. you can also use these two permission to use flashlight in your application.

    <uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera" />
SAURABH_12
  • 2,262
  • 1
  • 19
  • 19