Android Add <uses-feature> in Manifest
Solution 1
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>
Solution 2
<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
Solution 3
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" />
Jana
Updated on February 19, 2020Comments
-
Jana about 4 years
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?
-
MByD about 13 years+1 If you added
<uses-feature...>
example as well, it would be even better :) -
stan about 11 yearsYou copied and posted this from the dev site, and showed no effort to actually answer OP's question. Fail
-
Rupesh Yadav about 11 yearsya you are correct, i have done this because this is the best explanation
why to use <uses-feature> 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. -
Ramesh Miriyala over 10 yearsjust change the tags order like that and just look into the androidmanifest xml file dtd or xsd
-
Jaydev over 7 yearsCan't we simply say <uses-feature android:name="android.permission.CAMERA" android:required="false" /> ?
-
Rupesh Yadav over 7 years
<uses-feature>
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,<uses-permission>
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.