Skip to content

Commit

Permalink
[Android] Now takes UseFrontCameraIfAvailable into account, fixes #120
Browse files Browse the repository at this point in the history
  • Loading branch information
Redth committed Aug 5, 2014
1 parent 8ca58c0 commit cb518b1
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/ZXing.Net.Mobile/Android/ZXingSurfaceView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,17 @@ public void SurfaceCreated (ISurfaceHolder holder)
var found = false;
Android.Util.Log.Debug ("ZXing.Net.Mobile", "Found " + numCameras + " cameras...");

var whichCamera = CameraFacing.Back;

if (options.UseFrontCameraIfAvailable.HasValue && options.UseFrontCameraIfAvailable.Value)
whichCamera = CameraFacing.Front;

for (int i = 0; i < numCameras; i++)
{
Android.Hardware.Camera.GetCameraInfo(i, camInfo);
if (camInfo.Facing == CameraFacing.Back)
if (camInfo.Facing == whichCamera)
{
Android.Util.Log.Debug ("ZXing.Net.Mobile", "Found Back Camera, opening...");
Android.Util.Log.Debug ("ZXing.Net.Mobile", "Found " + whichCamera + " Camera, opening...");
camera = Android.Hardware.Camera.Open(i);
found = true;
break;
Expand All @@ -116,7 +121,7 @@ public void SurfaceCreated (ISurfaceHolder holder)

if (!found)
{
Android.Util.Log.Debug("ZXing.Net.Mobile", "Finding rear camera failed, opening camera 0...");
Android.Util.Log.Debug("ZXing.Net.Mobile", "Finding " + whichCamera + " camera failed, opening camera 0...");
camera = Android.Hardware.Camera.Open(0);
}
}
Expand Down

0 comments on commit cb518b1

Please sign in to comment.