Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to use Camera Lib QML to turn on/off Flash light of Android devices



  • Hello all, I have a question about how to use Camera Lib Qml, I 've written demo code to turn on/ off flash light of Android device but it hasn't run, I dont know why. My code below :

    Button {
            id: btn
            property bool isClicked: false
            anchors.centerIn: parent
            text: "Click"
    
            onClicked: {
                isClicked = !isClicked
                if (isClicked) {
                    camera.FlashOn
                } else {
                    camera.FlashOff
                }
            }
    }
    
     Camera {
                id: camera
                flash.mode: Camera.FlashTorch
            }
        
    

    I've tried Camera.FlashVideoLight, it run but i can't turn on/off with button onClicked, Can you tell me how to use it ?
    Thank you


  • Moderators

    @Drakel
    did you specify (Android API <23) in AndroidManifest.xml or request (Android API >= 26) the android.permission.CAMERA permission?



  • I used QT version 5.12.2 for windows with JDK 8.0, SDK 26.1.1 and NDK 19.2, it It automatically generates AndroidManifest.xml for me, I see the content of file has <uses-permission android:name="android.permission.CAMERA" /> , I think Qt has added permission. My devices test use android 4.4.2 and 9.0. Can you help to fix that
    Thank you in advance


  • Moderators

    @Drakel
    as i provided the link.
    You need to request the permission at runtime (at least once).

    Also see this, you will see in the Android settings menu if the app has the permission or not.


Log in to reply