0

I created a folder on android mobile.

Here is my code :

QDir mypath(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation));
    if(!mypath.cd("Plugin"))
    {
        if(mypath.mkdir("Plugin"))
            qDebug() << "path created";
        else
            qDebug() << "path not created";
    }

I open file manager on mobile phone, i can see that folder has been created. But when i connect my mobile phone to PC on the same direction that folder did not show up.

Can anybody where the problem is? Thank you

user2652023
  • 197
  • 2
  • 16

1 Answers1

0

You must call the MediaScannerConnection.scanFile for all the files you created.

for example Nexus 4 not showing files via MTP

to call java function you can write the following

#include <QAndroidJniObject>

void  CAndroid::rescanFolder(QString dest)
{

    QAndroidJniObject java_app("org/programm/java_app");

    QAndroidJniObject param = QAndroidJniObject::fromString(dest);

    java_app.callMethod<jint>("rescanFolder","(Ljava/lang/String;)I",param.object<jstring>());

}

and modify java code

int rescanFolder(String dest) {

    File[] files = new File(dest).listFiles(new FileFilter() {
        @Override
        public boolean accept(File pathname) {
            return pathname.isFile();
        }
    });

    if(files!=null)
    {

        String[] paths = new String[files.length];
        for (int co=0; co< files.length; co++)
        {
            paths[co] = files[co].getAbsolutePath();

        }

        MediaScannerConnection.scanFile(QtNative.activity(), paths, null, null);


        files = new File(dest).listFiles(new FileFilter() {
            @Override
            public boolean accept(File pathname) {

                return pathname.isDirectory();
            }
        });

        for (int co=0; co<files.length; co++)
            rescanFolder(files[co].getAbsolutePath());
    }
    return 0;
}
Community
  • 1
  • 1
user1277317
  • 127
  • 11