4

How do I detect if android phone has dual back camera

I tried

CameraManager manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
    try {
        for(String id: manager.getCameraIdList())
            Log.e("dualtest", id);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }

but it gives me only 2 ids 0 and 1.

Miki
  • 40,887
  • 13
  • 123
  • 202

3 Answers3

1

Nishant, I tested the same on my Mi A1 and found that I get only two cameras. Were you able to find an answer?

for(String camera_id : cameraManager.getCameraIdList()){
    Log.d(TAG, "Available Cameras: id: " + camera_id + " and rear facing = " + (cameraManager.getCameraCharacteristics(camera_id).get(CameraCharacteristics.LENS_FACING) == CameraCharacteristics.LENS_FACING_BACK));
}

Output:

Available Cameras: id: 0 and rear facing = true

Available Cameras: id: 1 and rear facing = false

Also found this link on LG dual camera access. It would be helpful if one can help on answering how to enable the second rear facing camera on Mi A1

Brandon Minnick
  • 13,342
  • 15
  • 65
  • 123
Sandeep
  • 21
  • 6
0

You can use Camera.getCameraInfo Like follows. If you use api lvl 9

List<Integer> camID = new ArrayList<Integer>();    
        for(int i=0;i<Camera.getNumberOfCameras();i++){
            CameraInfo cameraInfo = new CameraInfo();
            Camera.getCameraInfo(i,cameraInfo);
            if(cameraInfo.facing==CameraInfo.CAMERA_FACING_BACK) {
                camID.add(i);
                break;
            }
        }

If you are using api lvl 21 you can use Camera2 api

List<String> camID = new ArrayList<String>(); 

    CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
    for(String cameraId:manager.getCameraIdList()){
        CameraCharacteristics cameraCharacteristics = manager.getCameraCharacteristics(cameraId);
        Integer facing = cameraCharacteristics.get(CameraCharacteristics.LENS_FACING);
        if(facing==CameraMetadata.LENS_FACING_BACK) {
            camID.add(cameraId);
            break;
        }
    }

Reference

https://developer.android.com/reference/android/hardware/camera2/CameraManager.html

https://developer.android.com/reference/android/hardware/Camera.html#getCameraInfo(int,%20android.hardware.Camera.CameraInfo)

Nisal Edu
  • 7,237
  • 4
  • 28
  • 34
0

Just a personal opinion here, but I don't think that this is possible (although I don't have any proof for this). Usually, the 2 dual cameras are very different on their own: aperture, zoom, colours and so on. They may not work so well on their own, but do a great job when the software combines the input from both. But if the processing software is very good, you don't even need the dual camera setup (take Google's camera app which does an excellent job at this). In conclusion, there is a big variety of how this dual cameras are made, and if a single camera work on some setups, on others it may be totally useless. This is why I believe that even though you have 2 cameras on the back, they are treated as a single camera by the system. Also, given the amount of Android phones manufacturers, there would be hard to align all of them in order to develop an unified API. Depending on the manufacturer, they may give you some APIs to access only one camera, but that will work only on their phones, and until Google doesn't switch to the dual camera setup, I don't believe that there will be an API that provides this feature.

Iulian Popescu
  • 2,595
  • 4
  • 23
  • 31
  • @lulian the thing is i just need to give a feature if their is dual back camera on phone . so all i want is to know if dual back camera exists or not i searched a lot but i didn't get anything. –  Nov 15 '17 at 07:37
  • May I ask what feature? – Iulian Popescu Nov 15 '17 at 07:39
  • one feature is to give bokeh effect if possible –  Nov 15 '17 at 07:49
  • Well, this is already made by the 2 cameras plus the software (or if you are Google, only by the software). You don't have to do anything else. – Iulian Popescu Nov 15 '17 at 08:00
  • @lulian tell me one thin does both cameras captures 2 different pictures simultaneously and merge both later, or only 1 image is taken? –  Nov 15 '17 at 11:15
  • Not sure, but I believe that in a few words it works like this. The actual process is more complex – Iulian Popescu Nov 15 '17 at 18:04
  • To produce the boceh effect, don't you need a way to independently access the two cameras? On the face of it, LG is the first to provide SDK for that, see http://mobile.developer.lge.com/develop/sdks/lg-dual-camera/ (for V20, V10, G5) – Alex Cohn Dec 24 '17 at 09:25