Beispiel #1
0
        public void Torch(bool on)
        {
            if (!this.Context.PackageManager.HasSystemFeature(PackageManager.FeatureCameraFlash))
            {
                Android.Util.Log.Info("ZXING", "Flash not supported on this device");
                return;
            }

            if (!PlatformChecks.HasFlashlightPermission(this.Context))
            {
                var msg = "ZXing.Net.Mobile requires permission to use the Flash (" + PlatformChecks.PERMISSION_FLASHLIGHT + "), but was not found in your AndroidManifest.xml file.";
                Android.Util.Log.Error("ZXing.Net.Mobile", msg);

                throw new UnauthorizedAccessException(msg);
            }

            if (camera == null)
            {
                Android.Util.Log.Info("ZXING", "NULL Camera");
                return;
            }

            var p = camera.GetParameters();
            var supportedFlashModes = p.SupportedFlashModes;

            if (supportedFlashModes == null)
            {
                supportedFlashModes = new List <string>();
            }

            var flashMode = string.Empty;

            if (on)
            {
                if (supportedFlashModes.Contains(Android.Hardware.Camera.Parameters.FlashModeTorch))
                {
                    flashMode = Android.Hardware.Camera.Parameters.FlashModeTorch;
                }
                else if (supportedFlashModes.Contains(Android.Hardware.Camera.Parameters.FlashModeOn))
                {
                    flashMode = Android.Hardware.Camera.Parameters.FlashModeOn;
                }
            }
            else
            {
                if (supportedFlashModes.Contains(Android.Hardware.Camera.Parameters.FlashModeOff))
                {
                    flashMode = Android.Hardware.Camera.Parameters.FlashModeOff;
                }
            }

            if (!string.IsNullOrEmpty(flashMode))
            {
                p.FlashMode = flashMode;
                camera.SetParameters(p);
            }
        }
Beispiel #2
0
        void CheckPermissions()
        {
            var perf = PerformanceCounter.Start();

            Android.Util.Log.Debug("ZXing.Net.Mobile", "Checking Camera Permissions...");

            if (!PlatformChecks.HasCameraPermission(this.Context))
            {
                var msg = "ZXing.Net.Mobile requires permission to use the Camera (" + PlatformChecks.PERMISSION_CAMERA + "), but was not found in your AndroidManifest.xml file.";
                Android.Util.Log.Error("ZXing.Net.Mobile", msg);

                throw new UnauthorizedAccessException(msg);
            }

            PerformanceCounter.Stop(perf, "CheckPermissions took {0}ms");
        }