Create folder/file on internal storage of mobile device



  • i am developing an app that load stuff from the internet(server), so i want to store xml file on device to be accessible later even without internet.

    Firstly i want to create a folder for my app where i can store all the files i want..
    i tried the the following but its not working.

    
        QString appFolder(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/myappname");
        QDir homePath(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation));
    
    //check and create to the writable path
    if (homePath.exists()){
       homePath.mkdir("myappname");
    }else{
        QDir().mkpath(appFolder);
    }
    
    //just incase it was not created
    if (!homePath.cd("myappname")){
            homePath.mkpath("myappname");
    }
    

    i want somthing like these:
    0_1507191217841_Screenshot_2017-10-05-10-05-50.png


  • Moderators

    @chawila said in Create folder/file on internal storage of mobile device:

    i tried the the following but its not working.

    I am tired of guessing...
    Maybe you could tell us what exactly isn't working and at least on what mobile platform you are on. That might help a little, don't you think?



  • @raven-worx

    i`m not sure about what u want..

    device : HUAWEI P8 lite
    android version : 5.0.1


    i tested it by creating, writing and reading from file.
    and it looks like it is working, however i cant find the location where it created the folder and file..

    'i mean when browsing on the phone'


  • Moderators

    @chawila
    so all you need to know is what QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) returns? really?!



  • @raven-worx said in Create folder/file on internal storage of mobile device:

    QStandardPaths::AppDataLocation

    I know what it return.

    Returns the directory containing the user applications (either executables, application bundles, or shortcuts to them). This is a generic value. Note that installing applications may require additional, platform-specific operations. Files, folders or shortcuts in this directory are platform-specific.
    

    what i want to know is how to create a folder exactly next to whatsapp folder on the image i attached..


  • Moderators

    @chawila said in Create folder/file on internal storage of mobile device:

    what i want to know is how to create a folder exactly next to whatsapp folder on the image i attached..

    well why not asking this in the first place. Instead of "it's not working".

    Nevertheless, traverse over the other QStandardPaths and check what returnes the closest path.
    The internal storage is not the same on all devices and Android versions. Normally it is something like /storage/emulated/0/

    If non of the QStandardPaths return the desired path you will have to use JNI and call some methods on the Context (=Activity). E.g:


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.