
Originally Posted by
ChrisW67
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:
File dir = Environment.getExternalStorageDirectory(); // external to your application, not external to the machine
String path = dir.getAbsolutePath();
File dir = Environment.getExternalStorageDirectory(); // external to your application, not external to the machine
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:
QString localeStorage
= QStandardPaths
::writableLocation(QStandardPaths
::GenericDataLocation) + "/";
if(QSysInfo::productType() == "android") { qDebug() << "Yes, its android";
localeStorage += "Android/data/com.zf.inventory/files/";
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();
QString localeStorage = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/";
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();
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:
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/"
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/"
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:
QString localeStorage
= QStandardPaths
::writableLocation(QStandardPaths
::DownloadLocation);
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)
Bookmarks