Search code examples
androidmanifestandroid-camera2front-camera

Filter app for front camera devices only


I am building an app that requires a front camera to work, I can check in runtime the list of available cameras with CameraManager.getCameraCharacteristics(cameraId) and compare with CameraCharacteristics.LENS_FACING_FRONT

But is there a way in the camera2 api or using the android manifest to filter the application so that it can only be installed on devices that have a front camera?

This is what I have declared in AndroidManifest

<uses-feature
        android:name="android.hardware.camera2"
        android:required="true" />

<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
<uses-permission android:name="android.permission.RECORD_AUDIO" /> 
<uses-permission android:name="android.permission.CAMERA" />

Solution

  • I think you need to add this feature:

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

    But this ALSO assumes that your app uses a android.hardware.camera. And that's usually not a problem and devices with front camera usually have the back camera. But if you do not want that then add:

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