1

Problem is that I can't rename file, even create folder. Nothing helps. All rights granted. Read-write in manifest existing. What is happening - IDK

Checked rights with this code:

bool chch;
auto result = QtAndroid::checkPermission(QString("android.permission.WRITE_EXTERNAL_STORAGE"));

    if (result == QtAndroid::PermissionResult::Denied) {
        QtAndroid::PermissionResultMap resultHash = QtAndroid::requestPermissionsSync(QStringList({"android.permission.WRITE_EXTERNAL_STORAGE"}));

        if (resultHash["android.permission.WRITE_EXTERNAL_STORAGE"] == QtAndroid::PermissionResult::Denied)
            chch = false;

        else {
            /* Here is Your method to upload to storage * /

            chch = true;
        }
    }

    else {
        /* Here is Your method to upload to storage * /

        chch = true;
    }

Result is - TRUE;

So next tried code from this topic - Qt Android Directories

bool result;
QDir dir("/storage/emulated/0");
qDebug() << dir;
result = dir.mkdir("cache");
qDebug() << "mkdir(\"cache\") success: " << result;
QFile m_file(dir.path() + "/cache/cache.txt");
result = m_file.open(QFile::WriteOnly);
qDebug() << "open() success: " << result;
m_file.close();
result = m_file.rename(dir.path() + "/cache/cache.zip");
qDebug() << "rename() success: " << result;

Output:

D libNote_armeabi-v7a.so: mkdir("cache") success:  false
D libNote_armeabi-v7a.so: open() success:  false
D libNote_armeabi-v7a.so: rename() success:  false

When I directly with opendialog taking path, there's this:

content:/com.android.externalstorage.documents/tree/primary%3A

Force switching it to /storage/emulated/0 doesn't help.

In both cases result is FALSE, so I can't create folder, can't access to the files and can't rename them.

What is the problem?

There's no other code. Just simply tried with 1 button change filename to implement it in main app later.

Pls help, trying whole day.

  • You do not have write access to the root of external storage, regardless of those permissions. Particularly for a cache, use `getCacheDir()` or `getExternalCacheDir()` on `Context` to get a filesystem location that you can read from and write to. – CommonsWare Sep 29 '22 at 15:07
  • What is Android version of used device? – blackapps Sep 29 '22 at 18:25
  • @CommonsWare so how then apps like telegram or whatsapp or other ones creating folder in root? and BTW, I'm trying to write NOT it external storage, only internal. And that I getting FALSE very strange – Viola Jenkins Sep 30 '22 at 05:26
  • @blackapps clean android 10 (without any gui-upgrade, mui, miu or smth else) – Viola Jenkins Sep 30 '22 at 05:27
  • @CommonsWare and how then working some third-party apps (filemanagers)? they provide option to do anything on device storage, even external. – Viola Jenkins Sep 30 '22 at 05:58
  • On an Android 10 device you can request for legacy external storage in manifest file and your path to root of external storage would be ok. – blackapps Sep 30 '22 at 09:48
  • "so how then apps like telegram or whatsapp or other ones creating folder in root?" -- in some cases, they are pre-installed. In other cases, they have not been updated in years and will be removed from the Play Store soon. In still other cases, they use hacks that no longer work. "I'm trying to write NOT it external storage, only internal" -- `/storage/emulated/0` is [external storage](https://commonsware.com/blog/2019/10/08/storage-situation-external-storage.html), not [internal storage](https://commonsware.com/blog/2019/10/06/storage-situation-internal-storage.html). – CommonsWare Sep 30 '22 at 10:51
  • "how then working some third-party apps (filemanagers)?" -- they use `MANAGE_EXTERNAL_STORAGE` as a permission, because they can justify to Google and other app distribution sites that this permission is justified. – CommonsWare Sep 30 '22 at 10:53
  • @blackapps doesn't help anyway( added: android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/> nothing works(( – Viola Jenkins Sep 30 '22 at 12:33
  • @CommonsWare doesn't help anyway( added: android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/> nothing works(( – Viola Jenkins Sep 30 '22 at 12:36
  • That is not how you use `MANAGE_EXTERNAL_STORAGE`. See [the documentation](https://developer.android.com/training/data-storage/manage-all-files) and [this section](https://commonsware.com/R/pages/chap-scoped-007.html) of [this free book](https://commonsware.com/R). – CommonsWare Sep 30 '22 at 12:40
  • @CommonsWare okay, I'm did this. android.settings.action.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION, requested it and nothing happened. In debug - no such activity. But if there's not - how then working third-party file managers on my Phone? I need this func for only my phone which has Android 10. If there's some other way to bypass this would be great. Very need manage root storage. Making kind of cleaner for phone and media data editor. – Viola Jenkins Oct 03 '22 at 07:09
  • @CommonsWare and this W System.err: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.permission.WRITE_EXTERNAL_STORAGE cat=[android.intent.category.DEFAULT] dat=package:com.Note.app } – Viola Jenkins Oct 03 '22 at 08:32
  • With regards to `ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION`, that and `MANAGE_EXTERNAL_STORAGE` are new to Android 11. For Android 10, [add `android:requestLegacyExternalStorage="true"` to the `` element in your manifest](https://developer.android.com/training/data-storage/use-cases#opt-out-in-production-app). At that point, external storage will behave as it did in earlier versions of Android. This will not help with Android 11+, though. Regarding the final comment, you cannot put a `package:` `Uri` into a `WRITE_EXTERNAL_STORAGE` `Intent`. – CommonsWare Oct 03 '22 at 11:14
  • @CommonsWare yes, but when I'm checking permission with this - QtAndroid::checkPermission(QString("android.permission.WRITE_EXTERNAL_STORAGE")); getting TRUE, but anyway I cant edit data in storage. - Is set – Viola Jenkins Oct 03 '22 at 13:24

0 Answers0