PDA

View Full Version : setOfflineStoragePath() to "internal shared storage/Android/data/<APPNAME>/"



shokarta
16th April 2021, 16:14
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

ChrisW67
18th April 2021, 06:39
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 (https://stackoverflow.com/questions/46610819/how-to-get-absolute-path-of-internal-storage-in-android) think this is the function you are after:


File dir = Environment.getExternalStorageDirectory(); // external to your application, not external to the machine
String path = dir.getAbsolutePath();

except you want it from C++ (https://stackoverflow.com/questions/19568354/apps-path-for-external-storage-in-native-code) not Java.

shokarta
18th April 2021, 13:57
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 (https://stackoverflow.com/questions/46610819/how-to-get-absolute-path-of-internal-storage-in-android) think this is the function you are after:


File dir = Environment.getExternalStorageDirectory(); // external to your application, not external to the machine
String path = dir.getAbsolutePath();

except you want it from C++ (https://stackoverflow.com/questions/19568354/apps-path-for-external-storage-in-native-code) 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:

QString localeStorage = QStandardPaths::writableLocation(QStandardPaths::G enericDataLocation) + "/";
if(QSysInfo::productType() == "android") {
qDebug() << "Yes, its android";
localeStorage += "Android/data/com.zf.inventory/files/";

QDir myDir;
if(!myDir.exists(localeStorage))
{
qDebug() << "Dir" << localeStorage << "does NOT exist";
if(myDir.mkpath(localeStorage)) {qDebug() << "dir created";}
else {qDebug() << "dir not created";}
}
else { qDebug() << "Dir" << localeStorage << "ALREADY existed"; }
}

// Sets path for SQLite
engine.setOfflineStoragePath(localeStorage);
qDebug() << "setOfflineStoragePath:" << engine.offlineStoragePath();

it did debug (after several tries, so it did created the folrders in one of first tries i guess:

D libInventory_armeabi-v7a.so: Yes, its android
D libInventory_armeabi-v7a.so: Dir "/storage/emulated/0/Android/data/com.zf.inventory/files/" ALREADY existed
D libInventory_armeabi-v7a.so: setOfflineStoragePath: "/storage/emulated/0/Android/data/com.zf.inventory/files/"

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:

QString localeStorage = QStandardPaths::writableLocation(QStandardPaths::D ownloadLocation);
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)