63 QString &path = (*androidDirCache)[QLatin1String(directoryField)];
67 QJniObject dirField = QJniObject::getStaticField<jstring>(
"android/os/Environment",
69 if (!dirField.isValid())
72 QJniObject file = QJniObject::callStaticMethod<QtJniTypes::File>(
"android/os/Environment",
73 "getExternalStoragePublicDirectory",
74 dirField.object<jstring>());
78 return (path = getAbsolutePath(file));
87 QString &path = (*androidDirCache)[
"APPNAME_%1"_L1.arg(QLatin1StringView(directoryField))];
91 QJniObject appCtx = QAndroidApplication::context();
92 if (!appCtx.isValid())
95 QJniObject dirField = QJniObject::fromString(
""_L1);
96 if (directoryField && strlen(directoryField) > 0) {
97 dirField = QJniObject::getStaticField<QtJniTypes::Environment, jstring>(directoryField);
98 if (!dirField.isValid())
102 QJniObject file = appCtx.callMethod<QtJniTypes::File>(
"getExternalFilesDir",
103 dirField.object<jstring>());
108 return (path = getAbsolutePath(file));
181QString QStandardPaths::writableLocation(StandardLocation type)
184 case QStandardPaths::MusicLocation:
185 return getSdkBasedExternalDir(
"DIRECTORY_MUSIC");
186 case QStandardPaths::MoviesLocation:
187 return getSdkBasedExternalDir(
"DIRECTORY_MOVIES");
188 case QStandardPaths::PicturesLocation:
189 return getSdkBasedExternalDir(
"DIRECTORY_PICTURES");
190 case QStandardPaths::DocumentsLocation:
191 return getSdkBasedExternalDir(
"DIRECTORY_DOCUMENTS");
192 case QStandardPaths::DownloadLocation:
193 return getSdkBasedExternalDir(
"DIRECTORY_DOWNLOADS");
194 case QStandardPaths::GenericConfigLocation:
195 case QStandardPaths::ConfigLocation:
196 case QStandardPaths::AppConfigLocation:
197 return getFilesDir() + testDir() +
"/settings"_L1;
198 case QStandardPaths::StateLocation:
199 case QStandardPaths::GenericStateLocation:
200 return getFilesDir() + testDir() +
"/state"_L1;
201 case QStandardPaths::GenericDataLocation:
203 return QAndroidApplication::sdkVersion() >= 30 ?
204 getExternalFilesDir() + testDir() : getExternalStorageDirectory() + testDir();
206 case QStandardPaths::AppDataLocation:
207 case QStandardPaths::AppLocalDataLocation:
208 return getFilesDir() + testDir();
209 case QStandardPaths::GenericCacheLocation:
210 case QStandardPaths::RuntimeLocation:
211 case QStandardPaths::TempLocation:
212 case QStandardPaths::CacheLocation:
213 return getCacheDir() + testDir();
214 case QStandardPaths::DesktopLocation:
215 case QStandardPaths::HomeLocation:
216 return getFilesDir();
217 case QStandardPaths::ApplicationsLocation:
218 case QStandardPaths::FontsLocation:
219 case QStandardPaths::PublicShareLocation:
220 case QStandardPaths::TemplatesLocation:
228QStringList QStandardPaths::standardLocations(StandardLocation type)
230 QStringList locations;
232 if (type == MusicLocation) {
233 locations << getExternalFilesDir(
"DIRECTORY_MUSIC");
235 if (QNativeInterface::QAndroidApplication::sdkVersion() < 30) {
236 locations << getExternalStoragePublicDirectory(
"DIRECTORY_PODCASTS")
237 << getExternalStoragePublicDirectory(
"DIRECTORY_NOTIFICATIONS")
238 << getExternalStoragePublicDirectory(
"DIRECTORY_ALARMS");
240 locations << getExternalFilesDir(
"DIRECTORY_PODCASTS")
241 << getExternalFilesDir(
"DIRECTORY_NOTIFICATIONS")
242 << getExternalFilesDir(
"DIRECTORY_ALARMS");
243 }
else if (type == MoviesLocation) {
244 locations << getExternalFilesDir(
"DIRECTORY_MOVIES");
245 }
else if (type == PicturesLocation) {
246 locations << getExternalFilesDir(
"DIRECTORY_PICTURES");
247 }
else if (type == DocumentsLocation) {
248 locations << getExternalFilesDir(
"DIRECTORY_DOCUMENTS");
249 }
else if (type == DownloadLocation) {
250 locations << getExternalFilesDir(
"DIRECTORY_DOWNLOADS");
251 }
else if (type == AppDataLocation || type == AppLocalDataLocation) {
252 locations << getExternalFilesDir();
253 }
else if (type == CacheLocation) {
254 locations << getExternalCacheDir();
255 }
else if (type == FontsLocation) {
256 QString &fontLocation = (*androidDirCache)[QStringLiteral(
"FONT_LOCATION")];
257 if (!fontLocation.isEmpty()) {
258 locations << fontLocation;
260 const QByteArray ba = qgetenv(
"QT_ANDROID_FONT_LOCATION");
262 locations << (fontLocation = QDir::cleanPath(QString::fromLocal8Bit(ba)));
266 locations <<
"/system/fonts"_L1;
271 const QString writable = writableLocation(type);
272 if (!writable.isEmpty())
273 locations.prepend(writable);
275 locations.removeDuplicates();