Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Android camera widget aplication
Forum Updated to NodeBB v4.3 + New Features

Android camera widget aplication

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
13 Posts 4 Posters 1.3k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    slavisac
    wrote on last edited by
    #1

    Hello
    i trying to get photos from camera on android but no success.
    for now i can open camera with jnl and take photo but photo not stored on phone
    i use this class to open camera

    void radni::on_pushButton_3_clicked()
    {
    QAndroidJniObject ACTION_SET_TIMER = QAndroidJniObject::getStaticObjectField("android/provider/MediaStore","ACTION_IMAGE_CAPTURE", "Ljava/lang/String;");
    QAndroidJniObject intent("android/content/Intent","(Ljava/lang/String;)V",ACTION_SET_TIMER.object());
    QAndroidJniObject filename=QAndroidJniObject::fromString("coleeeeee1.jpg");
    QAndroidJniObject file("java/io/File","(Ljava/lang/String;)V",filename.object<jstring>());
    QAndroidJniObject uri = QAndroidJniObject::callStaticObjectMethod("android/net/Uri","fromFile", "(Ljava/io/File;)Landroid/net/Uri;", file.object());

                       QAndroidJniObject uristr=uri.callObjectMethod("toString", "()Ljava/lang/String;");
    
                        QAndroidJniObject key=QAndroidJniObject::fromString("MediaStore.EXTRA_OUTPUT");
                   //     intent.putExtra(MediaStore.EXTRA_OUTPUT, file);
    
              intent.callObjectMethod("putExtra","(Ljava/lang/String;Ljava/lang/String;)Landroid/content/Intent;",key.object(), uristr.object());
    
              QAndroidJniObject activity = QtAndroid::androidActivity();
    
              QAndroidJniObject packageManager = activity.callObjectMethod("getPackageManager","()Landroid/content/pm/PackageManager;");
              QAndroidJniObject componentName = intent.callObjectMethod("resolveActivity","(Landroid/content/pm/PackageManager;)Landroid/content/ComponentName;",packageManager.object());
              if (componentName.isValid()) {
    
                  QtAndroid::startActivity(intent, 42);
              } else {
                  qWarning() << "Unable to resolve activity";
              }
    

    }

    my knowegle of jnl is so poor

    Pablo J. RoginaP 1 Reply Last reply
    0
    • S slavisac

      Hello
      i trying to get photos from camera on android but no success.
      for now i can open camera with jnl and take photo but photo not stored on phone
      i use this class to open camera

      void radni::on_pushButton_3_clicked()
      {
      QAndroidJniObject ACTION_SET_TIMER = QAndroidJniObject::getStaticObjectField("android/provider/MediaStore","ACTION_IMAGE_CAPTURE", "Ljava/lang/String;");
      QAndroidJniObject intent("android/content/Intent","(Ljava/lang/String;)V",ACTION_SET_TIMER.object());
      QAndroidJniObject filename=QAndroidJniObject::fromString("coleeeeee1.jpg");
      QAndroidJniObject file("java/io/File","(Ljava/lang/String;)V",filename.object<jstring>());
      QAndroidJniObject uri = QAndroidJniObject::callStaticObjectMethod("android/net/Uri","fromFile", "(Ljava/io/File;)Landroid/net/Uri;", file.object());

                         QAndroidJniObject uristr=uri.callObjectMethod("toString", "()Ljava/lang/String;");
      
                          QAndroidJniObject key=QAndroidJniObject::fromString("MediaStore.EXTRA_OUTPUT");
                     //     intent.putExtra(MediaStore.EXTRA_OUTPUT, file);
      
                intent.callObjectMethod("putExtra","(Ljava/lang/String;Ljava/lang/String;)Landroid/content/Intent;",key.object(), uristr.object());
      
                QAndroidJniObject activity = QtAndroid::androidActivity();
      
                QAndroidJniObject packageManager = activity.callObjectMethod("getPackageManager","()Landroid/content/pm/PackageManager;");
                QAndroidJniObject componentName = intent.callObjectMethod("resolveActivity","(Landroid/content/pm/PackageManager;)Landroid/content/ComponentName;",packageManager.object());
                if (componentName.isValid()) {
      
                    QtAndroid::startActivity(intent, 42);
                } else {
                    qWarning() << "Unable to resolve activity";
                }
      

      }

      my knowegle of jnl is so poor

      Pablo J. RoginaP Offline
      Pablo J. RoginaP Offline
      Pablo J. Rogina
      wrote on last edited by Pablo J. Rogina
      #2

      @slavisac what if you try the QML camera example?

      Upvote the answer(s) that helped you solve the issue
      Use "Topic Tools" button to mark your post as Solved
      Add screenshots via postimage.org
      Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

      S 1 Reply Last reply
      0
      • Pablo J. RoginaP Pablo J. Rogina

        @slavisac what if you try the QML camera example?

        S Offline
        S Offline
        slavisac
        wrote on last edited by
        #3

        @Pablo-J.-Rogina how to implement with qt widget app

        jsulmJ J.HilkJ Pablo J. RoginaP 3 Replies Last reply
        0
        • S slavisac

          @Pablo-J.-Rogina how to implement with qt widget app

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @slavisac https://doc.qt.io/qt-5/qcamera.html

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          S 1 Reply Last reply
          0
          • jsulmJ jsulm

            @slavisac https://doc.qt.io/qt-5/qcamera.html

            S Offline
            S Offline
            slavisac
            wrote on last edited by
            #5

            @jsulm
            Qcamera viewfinder not working on android

            jsulmJ 1 Reply Last reply
            0
            • S slavisac

              @jsulm
              Qcamera viewfinder not working on android

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @slavisac Then I guess you can't do it with Qt widgets

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              S 1 Reply Last reply
              0
              • S slavisac

                @Pablo-J.-Rogina how to implement with qt widget app

                J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on last edited by
                #7

                @slavisac

                create a qml file with a Camera component, make sure to give it some object name eg: objectName: "camera"

                Load the qml file via QQuickWidget

                do the following inside your c++ class to get access to the QML Camera component

                ui->quickWidget->setSource(QUrl(QStringLiteral("qrc:/Camera/FrontCam.qml")));
                    camera = ui->quickWidget->rootObject()->findChild<QObject*>("camera")->property("mediaObject").value<QCamera*>();
                //camera is a QCamera  pointer
                

                Example taken from one of my projects


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                S 1 Reply Last reply
                1
                • jsulmJ jsulm

                  @slavisac Then I guess you can't do it with Qt widgets

                  S Offline
                  S Offline
                  slavisac
                  wrote on last edited by
                  #8

                  @jsulm
                  i use jnl code to open camera and see, can shot but could not save photo

                  1 Reply Last reply
                  0
                  • J.HilkJ J.Hilk

                    @slavisac

                    create a qml file with a Camera component, make sure to give it some object name eg: objectName: "camera"

                    Load the qml file via QQuickWidget

                    do the following inside your c++ class to get access to the QML Camera component

                    ui->quickWidget->setSource(QUrl(QStringLiteral("qrc:/Camera/FrontCam.qml")));
                        camera = ui->quickWidget->rootObject()->findChild<QObject*>("camera")->property("mediaObject").value<QCamera*>();
                    //camera is a QCamera  pointer
                    

                    Example taken from one of my projects

                    S Offline
                    S Offline
                    slavisac
                    wrote on last edited by
                    #9

                    @J.Hilk said in Android camera widget aplication:

                    objectName: "camera"

                    hi

                    i have error :
                    C:\Users\cole\Documents\R-Nalog\kamera.cpp:13: error: error: undefined reference to 'QQuickWidget::setSource(QUrl const&)'

                    0_1560415629759_problem.png

                    J.HilkJ 1 Reply Last reply
                    0
                    • S slavisac

                      @J.Hilk said in Android camera widget aplication:

                      objectName: "camera"

                      hi

                      i have error :
                      C:\Users\cole\Documents\R-Nalog\kamera.cpp:13: error: error: undefined reference to 'QQuickWidget::setSource(QUrl const&)'

                      0_1560415629759_problem.png

                      J.HilkJ Offline
                      J.HilkJ Offline
                      J.Hilk
                      Moderators
                      wrote on last edited by
                      #10

                      @slavisac
                      did you add
                      QT += quickwidgets to your project file ?

                      and clean & rerun qmake afterwards?


                      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                      Q: What's that?
                      A: It's blue light.
                      Q: What does it do?
                      A: It turns blue.

                      S 1 Reply Last reply
                      1
                      • J.HilkJ J.Hilk

                        @slavisac
                        did you add
                        QT += quickwidgets to your project file ?

                        and clean & rerun qmake afterwards?

                        S Offline
                        S Offline
                        slavisac
                        wrote on last edited by
                        #11

                        @J.Hilk
                        now is ok but QQuickWidget dont show on android (no rendering image)
                        Thank you

                        1 Reply Last reply
                        0
                        • S slavisac

                          @Pablo-J.-Rogina how to implement with qt widget app

                          Pablo J. RoginaP Offline
                          Pablo J. RoginaP Offline
                          Pablo J. Rogina
                          wrote on last edited by
                          #12

                          @slavisac said in Android camera widget aplication:

                          qt widget app

                          could you elaborate about this requirement? Why you cannot use QML approach?

                          Upvote the answer(s) that helped you solve the issue
                          Use "Topic Tools" button to mark your post as Solved
                          Add screenshots via postimage.org
                          Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                          S 1 Reply Last reply
                          0
                          • Pablo J. RoginaP Pablo J. Rogina

                            @slavisac said in Android camera widget aplication:

                            qt widget app

                            could you elaborate about this requirement? Why you cannot use QML approach?

                            S Offline
                            S Offline
                            slavisac
                            wrote on last edited by
                            #13

                            @Pablo-J.-Rogina

                            i finished app just need implement camera to take photos

                            1 Reply Last reply
                            0

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved