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. Qt and Android - How to launch camera by using Qandroidjniobject

Qt and Android - How to launch camera by using Qandroidjniobject

Scheduled Pinned Locked Moved Solved Mobile and Embedded
qtandroidandroidqt creatorqandroidjniobjecamera
3 Posts 2 Posters 845 Views
  • 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.
  • H Offline
    H Offline
    HemantZ
    wrote on 25 Jun 2020, 04:47 last edited by HemantZ
    #1

    I am new in Qt android app development. I want to open camera and take picture and get the path of image by using QtAndroid, and JNIObject.

    For example,
    Java code -

    Intent capture_image_intent = new Intent();
    capture_image_intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
    startActivityForResult(capture_image_intent, 101);
    

    I written this java code in Qt by using Qandroidjniobject. This is given below,
    Qt code -

    QAndroidJniObject ACTION_CAPTURE = QAndroidJniObject::fromString("android.provider.MediaStore.ACTION_IMAGE_CAPTURE");
                QAndroidJniObject intent("android/content/Intent");
                if (ACTION_CAPTURE.isValid() && intent.isValid())
                {
                    intent.callObjectMethod("setAction", "(Ljava/lang/String;)Landroid/content/Intent;", ACTION_CAPTURE.object<jstring>());
                    QtAndroid::startActivity(intent.object<jobject>(), 101, this);
                    qDebug() << "OK";
                }
                else
                {
                    qDebug() << "ERROR";
                }
    

    Now, my question is by using above qt code my app cannot launch Camera. So, please help me for finding what is the problem?

    1 Reply Last reply
    0
    • H Offline
      H Offline
      HemantZ
      wrote on 25 Jun 2020, 07:42 last edited by
      #2

      I solved this above problem in Qt by using Qandroidjniobject.

      For launching camera by using intent code is given below,

      QAndroidJniObject ACTION_IMAGE_CAPTURE = 
         QAndroidJniObject::getStaticObjectField("android/provider/MediaStore", 
         "ACTION_IMAGE_CAPTURE", "Ljava/lang/String;");
      QAndroidJniObject intent("android/content/Intent", "(Ljava/lang/String;)V", 
          ACTION_IMAGE_CAPTURE.object<jstring>());
      QtAndroid::startActivity(intent.object<jobject>(), 101, this);
      
      1 Reply Last reply
      2
      • M Offline
        M Offline
        Maurizio Parafati
        wrote on 22 Sept 2022, 07:55 last edited by
        #3

        How did you get the taken picture from the camera?

        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