17

I am pretty confused where to add the

uses-feature

tag in the manifest. I am using the camera in my app. I added permission but I'm confused where to add features in order to use front facing camera. Can you help?

Noha Kareem
  • 1,748
  • 1
  • 22
  • 32
Jana
  • 2,890
  • 5
  • 35
  • 45

4 Answers4

20

Add this under <manifest> tag, like this:

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
              package="com.lalllala">
       <uses-permission android:name="android.permission.INTERNET" />
       <uses-permission android:name="android.permission.VIBRATE" />
       <uses-feature android:name="android.hardware.camera" />
          <application android:icon="@drawable/icon" android:label="lalla" android:debuggable="true">

          </application>
    </manifest>
Vladimir Ivanov
  • 42,730
  • 18
  • 77
  • 103
5

<uses-feature> - Declares a single hardware or software feature that is used by the application.

The purpose of a declaration is to inform any external entity of the set of hardware and software features on which your application depends. The element offers a required attribute that lets you specify whether your application requires and cannot function without the declared feature, or whether it prefers to have the feature but can function without it. Because feature support can vary across Android devices, the element serves an important role in letting an application describe the device-variable features that it uses. read for more

Below is sample code to access Device Front Camera

public Camera openFrontFacingCamera() {
int cameraCount = 0;
Camera ffCam = null;
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();

// Find the total number of cameras available
cameraCount = Camera.getNumberOfCameras();

// Find the ID of the CAMERA_FACING_FRONT & open it
for (int camIdx = 0; camIdx < cameraCount; camIdx++) {
    Camera.getCameraInfo(camIdx, cameraInfo);
    if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
        try {
            ffCam = Camera.open(camIdx);
        } catch (RuntimeException e) {
            Log.e(TAG, "Camera failed to open: " + e.getLocalizedMessage());
        }
    }
}

    return ffCam;
}

Need following permissions

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

For more please read Google android developer API doc Camera, Camera.CameraInfo

Rupesh Yadav
  • 12,096
  • 4
  • 53
  • 70
  • 1
    You copied and posted this from the dev site, and showed no effort to actually answer OP's question. Fail – stan Feb 08 '13 at 18:14
  • 3
    ya you are correct, i have done this because this is the best explanation `why to use tag in manifest by Google 'android_developer' site`. and i copied text here to just have a short explanation & if person wish to read more then click to its page link. – Rupesh Yadav Feb 11 '13 at 13:22
  • Can't we simply say ? – Jaydev Oct 04 '16 at 10:46
  • `` Sole purpose is to inform any external entity of the set of hardware and software features on which your application depends. _In short we can say element of uses-feature describe the device-variable features that your application use._ where as, `` _Requests a permission that the application must be granted in order for it to operate correctly._ Permissions are granted by the user when the application is installed. Its not allowed to merge these two. – Rupesh Yadav Oct 05 '16 at 13:40
2

Add this under manifest tag:

<!-- Request the camera permission -->
    <uses-permission
        android:name="android.permission.CAMERA" />
    <uses-feature
        android:name="android.hardware.camera"
        android:required="true" />
Sani Kamal
  • 1,208
  • 16
  • 26
0

write tags order like this

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

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

    <application>

    </application>
</manifest>
juhan_h
  • 3,965
  • 4
  • 29
  • 35