Results 1 to 3 of 3

Thread: setOfflineStoragePath() to "internal shared storage/Android/data/<APPNAME>/"

  1. #1
    Join Date
    Jan 2019
    Posts
    21
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default setOfflineStoragePath() to "internal shared storage/Android/data/<APPNAME>/"

    Hello gurus,

    im looking to see how I can set the offlinestoragepath to the android folder "internal shared storage/Android/data/<APPNAME>/".
    Basicaly its because i need to store soem application files for public purposes where it can be downloaded just via plugging USB cable and browsing these public folders...
    and unfortunatelly, because the device is not rooted, after plugging usb cable and setting UBS to "Transfer files", i see only one drive on the device "Internal shared storage" as i dont use the external card.

    Than kyou

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: setOfflineStoragePath() to "internal shared storage/Android/data/<APPNAME>/"

    So you want to know how to determine a system path on Android so that you can address the location. Seems that Google and StackExchange think this is the function you are after:
    Qt Code:
    1. File dir = Environment.getExternalStorageDirectory(); // external to your application, not external to the machine
    2. String path = dir.getAbsolutePath();
    To copy to clipboard, switch view to plain text mode 
    except you want it from C++ not Java.

  3. #3
    Join Date
    Jan 2019
    Posts
    21
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: setOfflineStoragePath() to "internal shared storage/Android/data/<APPNAME>/"

    Quote Originally Posted by ChrisW67 View Post
    So you want to know how to determine a system path on Android so that you can address the location. Seems that Google and StackExchange think this is the function you are after:
    Qt Code:
    1. File dir = Environment.getExternalStorageDirectory(); // external to your application, not external to the machine
    2. String path = dir.getAbsolutePath();
    To copy to clipboard, switch view to plain text mode 
    except you want it from C++ not Java.
    Hello Chris,
    thank you for the input... this let me to google that this path belongs to "/storage/emulated/0/Android/data/"
    so as close as I could get to make it work is to use QStandardPaths::GenericDataLocation which gives me path to "/storage/emulated/0"
    so with little tweaking:
    Qt Code:
    1. QString localeStorage = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/";
    2. if(QSysInfo::productType() == "android") {
    3. qDebug() << "Yes, its android";
    4. localeStorage += "Android/data/com.zf.inventory/files/";
    5.  
    6. QDir myDir;
    7. if(!myDir.exists(localeStorage))
    8. {
    9. qDebug() << "Dir" << localeStorage << "does NOT exist";
    10. if(myDir.mkpath(localeStorage)) {qDebug() << "dir created";}
    11. else {qDebug() << "dir not created";}
    12. }
    13. else { qDebug() << "Dir" << localeStorage << "ALREADY existed"; }
    14. }
    15.  
    16. // Sets path for SQLite
    17. engine.setOfflineStoragePath(localeStorage);
    18. qDebug() << "setOfflineStoragePath:" << engine.offlineStoragePath();
    To copy to clipboard, switch view to plain text mode 

    it did debug (after several tries, so it did created the folrders in one of first tries i guess:
    Qt Code:
    1. D libInventory_armeabi-v7a.so: Yes, its android
    2. D libInventory_armeabi-v7a.so: Dir "/storage/emulated/0/Android/data/com.zf.inventory/files/" ALREADY existed
    3. D libInventory_armeabi-v7a.so: setOfflineStoragePath: "/storage/emulated/0/Android/data/com.zf.inventory/files/"
    To copy to clipboard, switch view to plain text mode 

    however the file (and mainly the directory "com.zf.inventory") was not there and even QT didnt return any error (SQLite database work fine)

    however trying:
    Qt Code:
    1. QString localeStorage = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
    To copy to clipboard, switch view to plain text mode 
    works fine for Downloads folder, where it basicaly treates automaticaly folder "Databases" and sqlite file is inside...
    but when im trying to mkdir/mkpath inside the Download folder (with appname or whatever) then same issue... no error but folder is not there, and offlineStoragePath() retunrs as it would be created

    any ideas how to get there? what could be wrong?

    EDIT: so it does create the folder via mkpath, but to se eit i have to remove the USB from the device and reconnect, refreshing doesnt help,
    however it automaticaly creates the folder Databases in there, but the sqlite file is not there


    Added after 1 31 minutes:


    YES, solution was very simple.
    engine.load() must go after the engine.setOfflineStoragePath(localeStorage)
    Last edited by shokarta; 18th April 2021 at 14:57.

Similar Threads

  1. Replies: 1
    Last Post: 14th November 2019, 21:55
  2. Replies: 4
    Last Post: 15th July 2012, 03:41
  3. Replies: 1
    Last Post: 7th April 2010, 22:46
  4. Replies: 3
    Last Post: 25th August 2009, 14:03
  5. QPixmap: X11 "memory leak" due to shared pixmap data?
    By chezifresh in forum Qt Programming
    Replies: 0
    Last Post: 21st April 2009, 20:53

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.