Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-52182

Android: QML Torch doesn't switch on

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Won't Do
    • Affects Version/s: 5.6.0
    • Fix Version/s: None
    • Component/s: Multimedia
    • Labels:
      None
    • Platform/s:
      Android

      Description

      Could be related to QTBUG-39318

      Tested on Android Lollilop 5 Samsung Galaxy S5

      Example of working Java code on this device:

      public class MyActivity extends org.qtproject.qt5.android.bindings.QtActivity
      {
        ...
      
        private Camera m_camera = null;
        private Camera.Parameters m_camera_parameters = null;
        private boolean m_torch_enabled = false;
      
        private boolean has_flash() {
          PackageManager package_manager = getPackageManager();
          return package_manager.hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
        }
      
        private void open_camera() {
          if (m_camera == null) {
            try {
      	m_camera = Camera.open();
      	m_camera_parameters = m_camera.getParameters();
            } catch (Exception e) {
      	// Camera is not available (in use or does not exist)
            }
          }
        }
      
        private void release_camera() {
          if (m_camera != null) {
            m_camera.stopPreview();
            m_camera.release();
            m_camera = null;
          }
        }
      
        private void _set_torch_mode(boolean enabled) {
          if (m_torch_enabled != enabled) {
            if (m_camera != null) {
      	String flash_mode = enabled ? Camera.Parameters.FLASH_MODE_TORCH : Camera.Parameters.FLASH_MODE_OFF;
      	m_camera_parameters.setFlashMode(flash_mode);
      	m_camera.setParameters(m_camera_parameters);
      	if (enabled)
      	  m_camera.startPreview();
      	else
      	  m_camera.stopPreview();
      	m_torch_enabled = enabled;
            }
          }
        }
      
        private void enable_torch() {
          _set_torch_mode(true);
        }
      
        private void disable_torch() {
          _set_torch_mode(false);
        }
      
        public void set_torch_mode(boolean enabled) {
          if (m_torch_enabled != enabled) {
            if (enabled) {
      	if (has_flash()) {
      	  open_camera();
      	  enable_torch();
      	}
            } else {
      	disable_torch();
      	release_camera();
            }
          }
        }
      

      Permissions:

        <uses-permission android:name="android.permission.CAMERA" />
        <uses-permission android:name="android.permission.FLASHLIGHT"/>
        <uses-feature android:name="android.hardware.camera" android:required="false"/>
      

        Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            • Assignee:
              valentyn.doroshchuk Valentyn Doroshchuk
              Reporter:
              fabricesalvaire fabrice salvaire
            • Votes:
              3 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Gerrit Reviews

                There are no open Gerrit changes