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?