Unsolved Not able to write on Android 10 although the WRITE_EXTERNAL_STORAGE is granted...
-
Hi,
I've been trying to deploy my app on a Android 10 armv8 (One plus 6) and I've an issue when trying to write files.
I'm getting this error:D ClemRemote: Download path: "/storage/emulated/0/Download" E ClemRemote: "the download folder is not writable..."
And also when changing to the sdcard:
E ClemRemote: New path is not writable... "/storage/emulated/0/Download" E ClemRemote: New path is not writable... "/sdcard/download"
That's from this simple test:
void ClementineRemote::updateDownloadPath(const QString &newPath) { QFileInfo fi(newPath); if (!fi.exists()) qCritical() << "New path doesn't exist... " << newPath; else if (!fi.isDir()) qCritical() << "New path is not a directory... " << newPath; else if (!fi.isWritable()) qCritical() << "New path is not writable... " << newPath; else { _downloadPath = newPath; _settings.setValue(sSettings[Settings::downloadPath], _downloadPath); } }
Any idea what could block the app to write?
-
@mbruel
IIRC since Android 10 you have to request those permissions from the user (first time only).
See https://doc.qt.io/qt-5/qtandroid.html#requestPermissions -
@raven-worx which permissions?
I've already requested WRITE_EXTERNAL_STORAGE and get it granted. So I don't understand why I'm not able to write a file...
I've done this: (cf here)#if defined(Q_OS_ANDROID) _downloadPath = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation); QtAndroid::PermissionResultMap res = QtAndroid::requestPermissionsSync({"android.permission.WRITE_EXTERNAL_STORAGE"}); if (res["android.permission.WRITE_EXTERNAL_STORAGE"] != QtAndroid::PermissionResult::Granted) return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
And I'm not returning.
If I check on the device the permission granted for my app, I can see it has Storage.
Do I need other permissions? -
Did you check that the folder exists ?
If memory serves well, the directory path is valid in the sense that if follows the platform guidelines but it will not exist until you create it as it would not make any sense to "pre-create" them for all applications you install on a device. -
@SGaist yes the folders exist. it passes
if (!fi.exists())
thenelse if (!fi.isDir())
and then fail onelse if (!fi.isWritable())
I don't understand why...
I've only seen this issue on my friend's device, I didn't have feedback on others yet...
But I'd like to make it work properly on any device... -
I don't remember if it's still possible be some of these cards could be physically locked for writing like the good old floppy drive. Could it be that ?
-
well I doubt it cause the app is neither able to write on the phone ram nor on the external sd card.
and he's able to use his phone normally with other apps, like taking pictures... -
this should only be done on API Level 30, but have you tried in your manifest - application to set
android:requestLegacyExternalStorage="true"