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

Access image captured by Camera app through JNI



  • Hello,

    I am trying to access an image that i want to capture through Android camera app and save it to a file,from my app. The camera activity starts, but after pressing the button to capture the image, it returns back to my app without saving any file. This is my code

     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("/mnt/sdcard/1.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("MediaStoreEXTRA_OUTPUT");
    
               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";
               }
    

    Can anybody tell me what i am doing wrong?
    Thank you in advance



  • For anybody who may be interested i found the solution,thanks to this


Log in to reply