1

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" />
adriandleon
  • 110
  • 1
  • 8

2 Answers2

1

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"/>
Xenolion
  • 12,035
  • 7
  • 33
  • 48
  • But can you clarify the difference between using android.hardware.camera2 and android.hardware.camera on the uses-feature? I am using Camera2 API from android.hardware.Camera2 in my app. – adriandleon Jul 13 '18 at 12:47
  • You are using Camera2 Api, thats great. But that does not mean you have to use `android.hardware.camera2` in the manifest uses features. Actual it does not even exist in the list here in the documentation https://developer.android.com/guide/topics/manifest/uses-feature-element#hw-features – Xenolion Jul 13 '18 at 19:39
0

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

See the <uses-feature> documentation for more about how to restrict your app to devices that have a front-facing camera, etc.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491