- Home /
Detect Android Rear Camera
Is there a way to detect that an Android device has a rear camera? I'm struggling to find out how this is possible in C#
My app needs to know if there is a rear camera and act accordingly. The presence of a front camera is irrelevant but I do need to know if a rear camera is available
Thanks
Answer by ahmedbenlakhdhar · Dec 12, 2014 at 09:10 PM
Try this:
WebCamDevice[] devices = WebCamTexture.devices;
WebCamDevice rearCamera;
foreach (WebCamDevice cam in devices){
if(!cam.isFrontFacing){
rearCamera = cam;
break;
}
}
bool hasARearCamera = (rearCamera != null);
This looks better thanks, I'm just trying to get Android Studio to load the app on my device and Ill post back the results thnaks
Answer by elpuerco63 · Dec 12, 2014 at 09:17 PM
Hi, thanks for such a speedy response!
I'm a bit confused with this code as I understand it to be seeing if there is a front camera and if there is one sets a variable to access it?
Is that correct? This is not actually what I am trying to achieve.
I need to know if the device has a rear camera not the front. My app needs a rear camera to be present and cannot make use of the front camera
Thanks
but maybe a modification of your code like so...might do it...
WebCamDevice[] devices = WebCamTexture.devices;
bool hasRearCamera = false;
foreach (WebCamDevice cam in devices){
if(!cam.isFrontFacing){
hasRearCamera = true;
break;
}
}
Sorry, I edited the answer. I hope it is correct now.
no it says !cam.isFrontFacing. That "!" means not. So it says if the camera is not the front, then it's the back and saves it.
Your answer
![](https://koobas.hobune.stream/wayback/20220613173919im_/https://answers.unity.com/themes/thub/images/avi.jpg)