From fc58ddfaea9c0a0b39fef20d03b8e7b80e5d1669 Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Sat, 21 Jan 2023 15:09:24 +0700 Subject: [PATCH] Make sure the full path of a taken photo / image is created on Android --- .../qfield/QFieldCameraPictureActivity.java | 14 +------------- .../qfield/QFieldGalleryPictureActivity.java | 12 ------------ .../platforms/android/androidplatformutilities.cpp | 9 +++++++++ 3 files changed, 10 insertions(+), 25 deletions(-) diff --git a/platform/android/src/ch/opengis/qfield/QFieldCameraPictureActivity.java b/platform/android/src/ch/opengis/qfield/QFieldCameraPictureActivity.java index 2ac1e2a54a..3947e8a8a6 100644 --- a/platform/android/src/ch/opengis/qfield/QFieldCameraPictureActivity.java +++ b/platform/android/src/ch/opengis/qfield/QFieldCameraPictureActivity.java @@ -103,13 +103,8 @@ protected void onActivityResult(int requestCode, int resultCode, if (requestCode == CAMERA_ACTIVITY) { if (resultCode == RESULT_OK) { File result = new File(prefix + pictureFilePath); - File path = result.getParentFile(); - path.mkdirs(); - path.setExecutable(true); - path.setReadable(true); - path.setWritable(true); - File pictureFile = new File(pictureTempFilePath); + Log.d(TAG, "Taken picture: " + pictureFile.getAbsolutePath()); try { InputStream in = new FileInputStream(pictureFile); @@ -119,13 +114,6 @@ protected void onActivityResult(int requestCode, int resultCode, e.printStackTrace(); } - // Let the android scan new media folders/files to make them - // visible through MTP - result.setReadable(true); - result.setWritable(true); - MediaScannerConnection.scanFile( - this, new String[] {path.toString()}, null, null); - Intent intent = this.getIntent(); intent.putExtra("PICTURE_IMAGE_FILENAME", prefix + pictureFilePath); diff --git a/platform/android/src/ch/opengis/qfield/QFieldGalleryPictureActivity.java b/platform/android/src/ch/opengis/qfield/QFieldGalleryPictureActivity.java index 694f873be3..5ea6a094c8 100644 --- a/platform/android/src/ch/opengis/qfield/QFieldGalleryPictureActivity.java +++ b/platform/android/src/ch/opengis/qfield/QFieldGalleryPictureActivity.java @@ -67,11 +67,6 @@ protected void onActivityResult(int requestCode, int resultCode, if (requestCode == GALLERY_ACTIVITY) { if (resultCode == RESULT_OK) { File result = new File(prefix + pictureFilePath); - File path = result.getParentFile(); - path.mkdirs(); - path.setExecutable(true); - path.setReadable(true); - path.setWritable(true); Log.d(TAG, "Selected picture: " + data.getData().toString()); try { @@ -85,13 +80,6 @@ protected void onActivityResult(int requestCode, int resultCode, Log.d(TAG, e.getMessage()); } - // Let the android scan new media folders/files to make them - // visible through MTP - result.setReadable(true); - result.setWritable(true); - MediaScannerConnection.scanFile( - this, new String[] {path.toString()}, null, null); - Intent intent = this.getIntent(); intent.putExtra("PICTURE_IMAGE_FILENAME", prefix + pictureFilePath); diff --git a/src/core/platforms/android/androidplatformutilities.cpp b/src/core/platforms/android/androidplatformutilities.cpp index c7c07402ba..c4d84b44d6 100644 --- a/src/core/platforms/android/androidplatformutilities.cpp +++ b/src/core/platforms/android/androidplatformutilities.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -345,6 +346,10 @@ PictureSource *AndroidPlatformUtilities::getCameraPicture( QQuickItem *parent, c if ( !checkCameraPermissions() ) return nullptr; + const QFileInfo destinationInfo( prefix + pictureFilePath ); + const QDir prefixDir( prefix ); + prefixDir.mkpath( destinationInfo.absolutePath() ); + QAndroidJniObject activity = QAndroidJniObject::fromString( QStringLiteral( "ch.opengis." APP_PACKAGE_NAME ".QFieldCameraPictureActivity" ) ); QAndroidJniObject intent = QAndroidJniObject( "android/content/Intent", "(Ljava/lang/String;)V", activity.object() ); QAndroidJniObject packageName = QAndroidJniObject::fromString( QStringLiteral( "ch.opengis." APP_PACKAGE_NAME ) ); @@ -384,6 +389,10 @@ PictureSource *AndroidPlatformUtilities::getGalleryPicture( QQuickItem *parent, { Q_UNUSED( parent ) + const QFileInfo destinationInfo( prefix + pictureFilePath ); + const QDir prefixDir( prefix ); + prefixDir.mkpath( destinationInfo.absolutePath() ); + QAndroidJniObject activity = QAndroidJniObject::fromString( QStringLiteral( "ch.opengis." APP_PACKAGE_NAME ".QFieldGalleryPictureActivity" ) ); QAndroidJniObject intent = QAndroidJniObject( "android/content/Intent", "(Ljava/lang/String;)V", activity.object() ); QAndroidJniObject packageName = QAndroidJniObject::fromString( QStringLiteral( "ch.opengis." APP_PACKAGE_NAME ) );