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

open android system camera occurs error using jni invoke java



  • java:

    public void callExternalCamera() {
        String action = "android.media.action.IMAGE_CAPTURE";
        Intent intent = new Intent(action);
        File extDir = android.os.Environment.getExternalStorageDirectory();
        String filename = "camera.jpg";
        File photo = new File(extDir, filename);
        Uri takePhotoSavedUri = Uri.fromFile( photo );
        intent.putExtra(MediaStore.EXTRA_OUTPUT, takePhotoSavedUri);
        int SHOOT_PHOTO = 1;
        startActivityForResult(intent, SHOOT_PHOTO);//This line caused, if delete this then it's ok.
    }
    

    qt:

    QAndroidJniObject activity = QtAndroid::androidActivity();
    activity.callMethod<void>("callExternalCamera","()V");
    

    error:

    F .s.p: java_vm_ext.cc:570] JNI DETECTED ERROR IN APPLICATION: JNI GetStaticMethodID called with pending exception android.os.FileUriExposedException: file:///storage/emulated/0/camera.jpg exposed beyond app through ClipData.Item.getUri()
    F .s.p: java_vm_ext.cc:570]   at void android.os.StrictMode.onFileUriExposed(android.net.Uri, java.lang.String) (StrictMode.java:2083)
    F .s.p: java_vm_ext.cc:570]   at void android.net.Uri.checkFileUriExposed(java.lang.String) (Uri.java:2395)
    F .s.p: java_vm_ext.cc:570]   at void android.content.ClipData.prepareToLeaveProcess(boolean, int) (ClipData.java:977)
    ...
    



Log in to reply