How to properly find Physical Camera ID, Android Studio

Viewed 375

So I'm trying to get the IDs of the Physical cameras on the phone (Xiaomi Red Mi Note 9). First I'm getting the IDs of the Logical cameras and use those IDs to get some information about the Physical ones, but every time I get "0" Physical cameras. Here is the code :

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       if( checkSelfPermission(Manifest.permission.CAMERA)==PackageManager.PERMISSION_GRANTED)
       {
           cameraManager=(CameraManager) getSystemService(Context.CAMERA_SERVICE);
           try {
               logicalCameraIdS=cameraManager.getCameraIdList();
               for(String logicalCameraId :logicalCameraIdS)
               {
                   cameraCharacteristics=cameraManager.getCameraCharacteristics(logicalCameraId);
                   Set<String> physicalCameraIdS=cameraCharacteristics.getPhysicalCameraIds();
                   if(physicalCameraIdS.size()>=2)
                   {
                       Log.i(" Message :  ", "We have more then One camera");
                   }
                   else{
                       Log.i(" Message :  ", "We Do not have multip[le cameras");
                   }


               }
           }
           catch (CameraAccessException e)
           {
               Log.i("Camera Error", e.toString());
           }



       }
       else
        {
            requestPermissions(new String[]{Manifest.permission.CAMERA},1);
        }
    }

Manifest permissions

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

Can someone explain what I'm doing wrong, and how to do it properly?

1 Answers

I'm answering this questions in order to prevent other people from making my mistake. As I stated in my question, I'm trying to run that code on an Xiaomi Redmi Note 9 and digging internet a little more I found out that Redmi Note 9S and 9Pro support the Android 11(API 30) while regular Redmi Note 9 doesn't yet. It runs on Android 10 (API 29) while the code that I wrote is for API 30 so only thing that I have to is just wait till an update to Android 11 for Redmi Note 9. Thanks for people that looked at this question and I consider the question answered.

Related